Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • syslab/tapir
  • aaasz/tapir
  • ashmrtnz/tapir
3 results
Show changes
Showing
with 148 additions and 245 deletions
// -*- mode: c++; c-file-style: "k&r"; c-basic-offset: 4 -*-
// vim: set ts=4 sw=4:
/***********************************************************************
*
* store/common/backend/lockserver.h:
......@@ -34,16 +33,14 @@
#include "lib/assert.h"
#include "lib/message.h"
#include <sys/time.h>
#include <map>
#include <queue>
#include <string>
#include <vector>
#include <unordered_map>
#include <unordered_set>
namespace spanstore {
#define LOCK_WAIT_TIMEOUT 5000
class LockServer
......@@ -100,6 +97,4 @@ private:
uint64_t writers;
};
} // namespace spanstore
#endif /* _LOCK_SERVER_H_ */
......@@ -4,16 +4,18 @@ d := $(dir $(lastword $(MAKEFILE_LIST)))
# gtest-based tests
#
GTEST_SRCS += $(addprefix $(d), \
kvstore-test.cc, versionstore-test.cc, lockserver-test.cc)
kvstore-test.cc \
versionstore-test.cc \
lockserver-test.cc)
$(d)kvstore-test: $(o)kvstore-test.o $(LIB-transport) $(LIB-common) $(LIB-backend) $(GTEST_MAIN)
$(d)kvstore-test: $(o)kvstore-test.o $(LIB-transport) $(LIB-store-common) $(LIB-store-backend) $(GTEST_MAIN)
TEST_BINS += $(d)kvstore-test
$(d)versionstore-test: $(o)versionstore-test.o $(LIB-transport) $(LIB-common) $(LIB-backend) $(GTEST_MAIN)
$(d)versionstore-test: $(o)versionstore-test.o $(LIB-transport) $(LIB-store-common) $(LIB-store-backend) $(GTEST_MAIN)
TEST_BINS += $(d)versionstore-test
$(d)lockserver-test: $(o)lockserver-test.o $(LIB-transport) $(LIB-common) $(LIB-backend) $(GTEST_MAIN)
$(d)lockserver-test: $(o)lockserver-test.o $(LIB-transport) $(LIB-store-common) $(LIB-store-backend) $(GTEST_MAIN)
TEST_BINS += $(d)lockserver-test
......@@ -28,7 +28,7 @@
*
**********************************************************************/
#include "store/common/backend/versionstore.h"
#include "store/common/backend/lockserver.h"
#include <gtest/gtest.h>
......@@ -36,16 +36,16 @@ TEST(LockServer, ReadLock)
{
LockServer s;
EXPECT_TRUE(s.LockForRead("x", 1));
EXPECT_TRUE(s.LockForRead("x", 2));
EXPECT_FALSE(s.LockForWrite("x", 3));
EXPECT_TRUE(s.lockForRead("x", 1));
EXPECT_TRUE(s.lockForRead("x", 2));
EXPECT_FALSE(s.lockForWrite("x", 3));
}
TEST(LockServer, WriteLock)
{
LockServer s;
EXPECT_TRUE(s.LockForWrite("x", 1));
EXPECT_FALSE(s.LockForRead("x", 2));
EXPECT_FALSE(s.LockForWrite("x", 3));
EXPECT_TRUE(s.lockForWrite("x", 1));
EXPECT_FALSE(s.lockForRead("x", 2));
EXPECT_FALSE(s.lockForWrite("x", 3));
}
......@@ -32,53 +32,26 @@
#include <gtest/gtest.h>
TEST(VersionedKVStore, Put)
{
VersionedKVStore store;
EXPECT_TRUE(store.put("test1", "abc"));
EXPECT_TRUE(store.put("test2", "def"));
EXPECT_TRUE(store.put("test1", "xyz"));
EXPECT_TRUE(store.put("test3", "abc"));
}
TEST(VersionedKVStore, Get)
{
VersionedKVStore store;
pair<Timestamp, std::string> val;
std::pair<Timestamp, std::string> val;
EXPECT_TRUE(store.put("test1", "abc"));
store.put("test1", "abc", Timestamp(10));
EXPECT_TRUE(store.get("test1", val));
EXPECT_EQ(val[1], "abc");
EXPECT_EQ(val.second, "abc");
EXPECT_EQ(Timestamp(10), val.first);
EXPECT_TRUE(store.put("test2", "def"));
store.put("test2", "def", Timestamp(10));
EXPECT_TRUE(store.get("test2", val));
EXPECT_EQ(val[1], "def");
EXPECT_EQ(val.second, "def");
EXPECT_EQ(Timestamp(10), val.first);
EXPECT_TRUE(store.put("test1", "xyz"));
store.put("test1", "xyz", Timestamp(11));
EXPECT_TRUE(store.get("test1", val));
EXPECT_EQ(val[1], "xyz");
}
TEST(VersionedKVStore, VersionedGet)
{
VersionedKVStore store;
Timestamp time;
Timestamp time2;
std::string val;
EXPECT_TRUE(store.put("test1", "abc", time));
EXPECT_TRUE(store.get("test1", val, time));
EXPECT_EQ(val, "abc");
EXPECT_TRUE(store.put("test2", "def", time2));
EXPECT_TRUE(store.get("test2", val, time2));
EXPECT_EQ(val, "def");
EXPECT_TRUE(store.put("test1", "xyz", time2));
EXPECT_TRUE(store.get("test1", val, time2));
EXPECT_EQ(val, "xyz");
EXPECT_EQ(val.second, "xyz");
EXPECT_EQ(Timestamp(11), val.first);
EXPECT_TRUE(store.get("test1", val, time));
EXPECT_EQ(val, "abc");
EXPECT_TRUE(store.get("test1", Timestamp(10), val));
EXPECT_EQ(val.second, "abc");
}
// -*- mode: c++; c-file-style: "k&r"; c-basic-offset: 4 -*-
// vim: set ts=4 sw=4:
/***********************************************************************
*
* store/common/frontend/shardclient.cc
* Client interface for a single replicated shard.
* store/txnstore/lib/txnstore.h:
* Interface for a single node transactional store serving as a
* server-side backend
*
* Copyright 2015 Irene Zhang <iyzhang@cs.washington.edu>
* Naveen Kr. Sharma <nksharma@cs.washington.edu>
* Copyright 2013-2015 Irene Zhang <iyzhang@cs.washington.edu>
* Naveen Kr. Sharma <naveenks@cs.washington.edu>
* Dan R. K. Ports <drkp@cs.washington.edu>
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
......@@ -30,72 +31,64 @@
*
**********************************************************************/
#include "common/txnclient.h"
#include "store/common/backend/txnstore.h"
using namespace std;
TxnClient::TxnClient() { }
TxnClient::~TxnClient() { }
TxnStore::TxnStore() {}
TxnStore::~TxnStore() {}
void
TxnClient::Begin(uint64_t id)
{
Panic("Unimplemented BEGIN");
}
void
TxnClient::Get(uint64_t id,
const string &key,
Promise *promise)
int
TxnStore::Get(uint64_t id, const string &key, pair<Timestamp, string> &value)
{
Panic("Unimplemented GET");
return;
return 0;
}
void
TxnClient::Get(uint64_t id,
const string &key,
const Timestamp &timestamp,
Promise *promise)
int
TxnStore::Get(uint64_t id, const string &key, const Timestamp &timestamp,
pair<Timestamp, string> &value)
{
Panic("Unimplemented GET");
return;
return 0;
}
void
TxnClient::Put(uint64_t id,
const string &key,
const string &value,
Promise *promise)
int
TxnStore::Put(uint64_t id, const string &key, const string &value)
{
Panic("Unimplemented PUT");
return;
return 0;
}
void
TxnClient::Prepare(uint64_t id,
const Transaction &txn,
const Timestamp &timestamp,
Promise *promise)
int
TxnStore::Prepare(uint64_t id, const Transaction &txn)
{
Panic("Unimplemented PREPARE");
return 0;
}
int
TxnStore::Prepare(uint64_t id, const Transaction &txn,
const Timestamp &timestamp, Timestamp &proposed)
{
Panic("Unimplemented PREPARE");
return 0;
}
void
TxnClient::Commit(uint64_t id,
const Transaction &txn,
uint64_t timestamp,
Promise *promise)
TxnStore::Commit(uint64_t id, uint64_t timestamp)
{
Panic("Unimplemented COMMIT");
return;
}
void
TxnClient::Abort(uint64_t id,
const Transaction &txn,
Promise *promise)
TxnStore::Abort(uint64_t id, const Transaction &txn)
{
Panic("Unimplemented ABORT");
return;
}
void
TxnStore::Load(const string &key, const string &value, const Timestamp &timestamp)
{
Panic("Unimplemented LOAD");
}
// -*- mode: c++; c-file-style: "k&r"; c-basic-offset: 4 -*-
// vim: set ts=4 sw=4:
/***********************************************************************
*
* common/txnstore.h:
* store/txnstore/lib/txnstore.h:
* Interface for a single node transactional store serving as a
* server-side backend
*
* Copyright 2013-2015 Irene Zhang <iyzhang@cs.washington.edu>
* Naveen Kr. Sharma <naveenks@cs.washington.edu>
* Dan R. K. Ports <drkp@cs.washington.edu>
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use, copy,
* modify, merge, publish, distribute, sublicense, and/or sell copies
* of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
**********************************************************************/
#ifndef _TXN_STORE_H_
#define _TXN_STORE_H_
#include "paxos-lib/lib/assert.h"
#include "paxos-lib/lib/message.h"
#include "common/transaction.h"
#include "common/timestamp.h"
// Reply types
#define REPLY_OK 0
#define REPLY_FAIL 1
#define REPLY_RETRY 2
#define REPLY_ABSTAIN 3
#define REPLY_TIMEOUT 4
#define REPLY_NETWORK_FAILURE 5
#define REPLY_MAX 6
#include "lib/assert.h"
#include "lib/message.h"
#include "store/common/timestamp.h"
#include "store/common/transaction.h"
class TxnStore
{
......
// -*- mode: c++; c-file-style: "k&r"; c-basic-offset: 4 -*-
// vim: set ts=4 sw=4:
/***********************************************************************
*
* store/common/backend/versionstore.cc:
......@@ -29,7 +28,7 @@
*
**********************************************************************/
#include "versionstore.h"
#include "store/common/backend/versionstore.h"
using namespace std;
......
// -*- mode: c++; c-file-style: "k&r"; c-basic-offset: 4 -*-
// vim: set ts=4 sw=4:
/***********************************************************************
*
* store/common/backend/versionstore.cc:
......@@ -39,12 +38,9 @@
#include <set>
#include <map>
#include <unordered_map>
#include <fstream>
#include <iostream>
class VersionedKVStore
{
public:
VersionedKVStore();
~VersionedKVStore();
......
syntax = "proto2";
message TimestampMessage {
required uint64 timestamp = 1;
required uint64 id = 2;
required uint64 id = 1;
required uint64 timestamp = 2;
}
message ReadMessage {
......
d := $(dir $(lastword $(MAKEFILE_LIST)))
SRCS += $(addprefix $(d), \
bufferclient.cc client.cc shardclient.cc)
SRCS += $(addprefix $(d), bufferclient.cc)
LIB-frontend := $(o)bufferclient.o $(o)txnclient.o $(o)client.o
LIB-store-frontend := $(o)bufferclient.o
// -*- mode: c++; c-file-style: "k&r"; c-basic-offset: 4 -*-
// vim: set ts=4 sw=4:
/***********************************************************************
*
* store/common/frontend/bufferclient.cc:
......@@ -29,7 +28,7 @@
*
**********************************************************************/
#include "bufferclient.h"
#include "store/common/frontend/bufferclient.h"
using namespace std;
......
// -*- mode: c++; c-file-style: "k&r"; c-basic-offset: 4 -*-
// vim: set ts=4 sw=4:
/***********************************************************************
*
* store/common/frontend/bufferclient.h:
......@@ -32,14 +31,11 @@
#ifndef _BUFFER_CLIENT_H_
#define _BUFFER_CLIENT_H_
#include "paxos-lib/lib/assert.h"
#include "paxos-lib/lib/message.h"
#include "paxos-lib/common/client.h"
#include "common/transaction.h"
#include "common/promise.h"
#include "common/txnclient.h"
#include <string>
#include "lib/assert.h"
#include "lib/message.h"
#include "store/common/promise.h"
#include "store/common/transaction.h"
#include "store/common/frontend/txnclient.h"
class BufferClient
{
......
// -*- mode: c++; c-file-style: "k&r"; c-basic-offset: 4 -*-
// vim: set ts=4 sw=4:
/***********************************************************************
*
* common/client.cc:
* Interface for a multiple shard transactional client.
*
**********************************************************************/
#include "common/client.h"
using namespace std;
Client::Client() { }
Client::~Client() { }
void
Client::Begin()
{
Panic("BEGIN Unimplemented");
}
int
Client::Get(const string &key, string &value)
{
Panic("GET Unimplemented");
return 0;
}
int
Client::Put(const string &key, const string &value)
{
Panic("PUT Unimplemented");
return 0;
}
bool
Client::Commit()
{
Panic("COMMIT Unimplemented");
return false;
}
void
Client::Abort()
{
Panic("ABORT Unimplemented");
}
vector<int>
Client::Stats()
{
Panic("STATS Unimplemented");
vector<int> v;
return v;
}
/* Takes a key and number of shards; returns shard corresponding to key. */
uint64_t
Client::key_to_shard(const string &key, uint64_t nshards)
{
uint64_t hash = 5381;
const char* str = key.c_str();
for (unsigned int i = 0; i < key.length(); i++) {
hash = ((hash << 5) + hash) + (uint64_t)str[i];
}
return (hash % nshards);
}
// -*- mode: c++; c-file-style: "k&r"; c-basic-offset: 4 -*-
// vim: set ts=4 sw=4:
/***********************************************************************
*
* common/client.h:
......@@ -10,37 +9,46 @@
#ifndef _CLIENT_API_H_
#define _CLIENT_API_H_
#include "paxos-lib/lib/assert.h"
#include "paxos-lib/lib/message.h"
#include "lib/assert.h"
#include "lib/message.h"
#include <string>
#include <vector>
class Client
{
public:
Client();
~Client();
Client() {};
virtual ~Client() {};
// Begin a transaction.
virtual void Begin();
virtual void Begin() = 0;
// Get the value corresponding to key.
virtual int Get(const std::string &key, std::string &value);
virtual int Get(const std::string &key, std::string &value) = 0;
// Set the value for the given key.
virtual int Put(const std::string &key, const std::string &value);
virtual int Put(const std::string &key, const std::string &value) = 0;
// Commit all Get(s) and Put(s) since Begin().
virtual bool Commit();
virtual bool Commit() = 0;
// Abort all Get(s) and Put(s) since Begin().
virtual void Abort();
virtual void Abort() = 0;
// Returns statistics (vector of integers) about most recent transaction.
virtual std::vector<int> Stats();
virtual std::vector<int> Stats() = 0;
// Sharding logic: Given key, generates a number b/w 0 to nshards-1
uint64_t key_to_shard(const std::string &key, uint64_t nshards);
uint64_t key_to_shard(const std::string &key, uint64_t nshards) {
uint64_t hash = 5381;
const char* str = key.c_str();
for (unsigned int i = 0; i < key.length(); i++) {
hash = ((hash << 5) + hash) + (uint64_t)str[i];
}
return (hash % nshards);
};
};
#endif /* _CLIENT_API_H_ */
// -*- mode: c++; c-file-style: "k&r"; c-basic-offset: 4 -*-
// vim: set ts=4 sw=4:
/***********************************************************************
*
* store/common/frontend/shardclient.cc
* store/common/frontend/txnclient.h
* Client interface for a single replicated shard.
*
* Copyright 2015 Irene Zhang <iyzhang@cs.washington.edu>
* Naveen Kr. Sharma <nksharma@cs.washington.edu>
* Naveen Kr. Sharma <naveenks@cs.washington.edu>
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
......@@ -33,9 +32,10 @@
#ifndef _TXN_CLIENT_H_
#define _TXN_CLIENT_H_
#include "common/timestamp.h"
#include "common/promise.h"
#include "common/transaction.h"
#include "store/common/promise.h"
#include "store/common/timestamp.h"
#include "store/common/transaction.h"
#include <string>
#define DEFAULT_TIMEOUT_MS 250
......@@ -58,44 +58,44 @@
class TxnClient
{
public:
TxnClient();
~TxnClient();
TxnClient() {};
virtual ~TxnClient() {};
// Begin a transaction.
virtual void Begin(uint64_t id);
virtual void Begin(uint64_t id) = 0;
// Get the value corresponding to key (valid at given timestamp).
virtual void Get(uint64_t id,
const std::string &key,
Promise *promise = NULL);
Promise *promise = NULL) = 0;
virtual void Get(uint64_t id,
const std::string &key,
const Timestamp &timestamp,
Promise *promise = NULL);
Promise *promise = NULL) = 0;
// Set the value for the given key.
virtual void Put(uint64_t id,
const std::string &key,
const std::string &value,
Promise *promise = NULL);
Promise *promise = NULL) = 0;
// Prepare the transaction.
virtual void Prepare(uint64_t id,
const Transaction &txn,
const Timestamp &timestamp = Timestamp(),
Promise *promise = NULL);
Promise *promise = NULL) = 0;
// Commit all Get(s) and Put(s) since Begin().
virtual void Commit(uint64_t id,
const Transaction &txn = Transaction(),
uint64_t timestamp = 0,
Promise *promise = NULL);
Promise *promise = NULL) = 0;
// Abort all Get(s) and Put(s) since Begin().
virtual void Abort(uint64_t id,
const Transaction &txn = Transaction(),
Promise *promise = NULL);
Promise *promise = NULL) = 0;
};
#endif /* _TXN_CLIENT_H_ */
// -*- mode: c++; c-file-style: "k&r"; c-basic-offset: 4 -*-
// vim: set ts=4 sw=4:
/***********************************************************************
*
* store/common/promise.h
......@@ -29,7 +28,7 @@
*
**********************************************************************/
#include "promise.h"
#include "store/common/promise.h"
using namespace std;
......
// -*- mode: c++; c-file-style: "k&r"; c-basic-offset: 4 -*-
// vim: set ts=4 sw=4:
/***********************************************************************
*
* store/common/promise.h
* Simple promise implementation.
*
* Copyright 2015 Irene Zhang <iyzhang@cs.washington.edu>
* Naveen Kr. Sharma <nksharma@cs.washington.edu>
* Naveen Kr. Sharma <naveenks@cs.washington.edu>
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
......@@ -36,7 +35,8 @@
#include "lib/assert.h"
#include "lib/message.h"
#include "lib/transport.h"
#include "transaction.h"
#include "store/common/transaction.h"
#include <condition_variable>
#include <mutex>
......
// -*- mode: c++; c-file-style: "k&r"; c-basic-offset: 4 -*-
// vim: set ts=4 sw=4:
/***********************************************************************
*
* common/timestamp.cc:
......@@ -7,7 +6,7 @@
*
**********************************************************************/
#include "timestamp.h"
#include "store/common/timestamp.h"
void
Timestamp::operator=(const Timestamp &t)
......
// -*- mode: c++; c-file-style: "k&r"; c-basic-offset: 4 -*-
// vim: set ts=4 sw=4:
/***********************************************************************
*
* common/timestamp.h
......
// -*- mode: c++; c-file-style: "k&r"; c-basic-offset: 4 -*-
// vim: set ts=4 sw=4:
/***********************************************************************
*
* tracer.cc:
......@@ -7,7 +6,7 @@
*
**********************************************************************/
#include "tracer.h"
#include "store/common/tracer.h"
using namespace std;
......