This commit is contained in:
Diptanshu Kakwani 2021-01-08 16:02:31 +05:30
Родитель 85a27b9d03
Коммит 80a1b3853d
6 изменённых файлов: 25 добавлений и 7 удалений

Просмотреть файл

@ -5,6 +5,12 @@ set(CMAKE_CXX_STANDARD 14)
add_executable(mock_key_value_store kv_store/src/main.cpp) add_executable(mock_key_value_store kv_store/src/main.cpp)
if(MSVC)
target_compile_options(mock_key_value_store PRIVATE /W4)
else()
target_compile_options(mock_key_value_store PRIVATE -Wall -Wextra -pedantic)
endif()
target_link_libraries(mock_key_value_store mock_kv_store) target_link_libraries(mock_key_value_store mock_kv_store)
enable_testing() enable_testing()

Просмотреть файл

@ -24,6 +24,10 @@ namespace mockdb {
this->store = store; this->store = store;
} }
virtual ~consistency_checker() {
// Pass
}
virtual bool is_consistent(const transaction<K, V> *new_tx) = 0; virtual bool is_consistent(const transaction<K, V> *new_tx) = 0;
protected: protected:
const kv_store<K, V> *store; const kv_store<K, V> *store;
@ -63,7 +67,7 @@ namespace mockdb {
return true; return true;
// Check if all dependent_txs are committed before tx_id // Check if all dependent_txs are committed before tx_id
int committed_count = 0; size_t committed_count = 0;
for (auto tx : this->store->get_history()) { for (auto tx : this->store->get_history()) {
if (dependent_txs.find(tx->get_tx_id()) != dependent_txs.end()) if (dependent_txs.find(tx->get_tx_id()) != dependent_txs.end())
committed_count++; committed_count++;

Просмотреть файл

@ -13,9 +13,13 @@ namespace mockdb {
virtual K get_key() const { virtual K get_key() const {
return this->key; return this->key;
} }
virtual ~operation_param() {
// Pass
}
protected: protected:
K key; K key;
}; };
template <typename K, typename V> template <typename K, typename V>

Просмотреть файл

@ -10,6 +10,10 @@ namespace mockdb {
template <typename K, typename V> template <typename K, typename V>
class operation_response { class operation_response {
public: public:
virtual ~operation_response() {
// Pass
}
virtual bool is_successful() { virtual bool is_successful() {
return success; return success;
} }
@ -34,8 +38,8 @@ namespace mockdb {
long get_written_by_tx_id() const { long get_written_by_tx_id() const {
return written_by_tx_id; return written_by_tx_id;
} }
void set_written_by_tx_id(long value) { void set_written_by_tx_id(long tx_id) {
written_by_tx_id = value; written_by_tx_id = tx_id;
} }
private: private:
const K key; const K key;

Просмотреть файл

@ -33,8 +33,8 @@ namespace mockdb {
virtual void init_consistency_checker(const kv_store <K, V> *store) = 0; virtual void init_consistency_checker(const kv_store <K, V> *store) = 0;
// By default it picks one transaction response at random // By default it picks one transaction response at random
virtual GET_response<K, V> *select_read_response(transaction<K, V> *tx, virtual GET_response<K, V> *select_read_response(transaction<K, V> *,
GET_operation<K, V> *op, GET_operation<K, V> *,
std::vector<GET_response<K, V> *> candidates) { std::vector<GET_response<K, V> *> candidates) {
int idx = std::rand() % candidates.size(); int idx = std::rand() % candidates.size();
return candidates[idx]; return candidates[idx];

Просмотреть файл

@ -9,7 +9,7 @@
#include <string> #include <string>
int main(int argc, char* argv[]) { int main() {
mockdb::kv_store<std::string, int> *store; mockdb::kv_store<std::string, int> *store;
mockdb::read_response_selector<std::string, int> *get_next_tx; mockdb::read_response_selector<std::string, int> *get_next_tx;