Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add catalog test #9

Merged
merged 2 commits into from
Sep 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/storage/meta/catalog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ NewCatalog::NewCatalog(SharedPtr<String> dir)
: current_dir_(std::move(dir)) {
}

// do not only use this method to create database
// it will not record database in transaction, so when you commit transaction
// it will lost operation
// use Txn::CreateDatabase instead
EntryResult
NewCatalog::CreateDatabase(NewCatalog* catalog,
const String& db_name,
Expand Down Expand Up @@ -48,6 +52,10 @@ NewCatalog::CreateDatabase(NewCatalog* catalog,
return res;
}

// do not only use this method to drop database
// it will not record database in transaction, so when you commit transaction
// it will lost operation
// use Txn::DropDatabase instead
EntryResult
NewCatalog::DropDatabase(NewCatalog* catalog,
const String& db_name,
Expand Down Expand Up @@ -115,8 +123,6 @@ NewCatalog::Databases(NewCatalog* catalog, Txn* txn) {

nlohmann::json
NewCatalog::Serialize(const NewCatalog* catalog) {
SharedPtr<String> current_dir_{nullptr};

nlohmann::json json_res;

json_res["current_dir"] = *catalog->current_dir_;
Expand Down
29 changes: 15 additions & 14 deletions src/storage/meta/db_meta.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
//

#include "db_meta.h"
#include "common/types/internal_types.h"
#include "main/logger.h"
#include "common/utility/defer_op.h"
#include "storage/txn/txn_manager.h"
Expand Down Expand Up @@ -33,7 +34,7 @@ DBMeta::CreateNewEntry(DBMeta* db_meta,
res = db_entry.get();
db_meta->entry_list_.emplace_front(std::move(db_entry));

// rw_locker_.unlock();

LOG_TRACE("New database entry is added.");
return {res, nullptr};
} else {
Expand All @@ -50,8 +51,7 @@ DBMeta::CreateNewEntry(DBMeta* db_meta,
}

DBEntry* header_db_entry = (DBEntry*)header_base_entry;
if(header_db_entry->commit_ts_ < UNCOMMIT_TS) {
// Committed
if(header_db_entry->Committed()) {
if(begin_ts > header_db_entry->commit_ts_) {
if(header_db_entry->deleted_) {
// No conflict
Expand Down Expand Up @@ -144,8 +144,7 @@ DBMeta::DropNewEntry(DBMeta* db_meta, u64 txn_id, TxnTimeStamp begin_ts, TxnMana
}

DBEntry* header_db_entry = (DBEntry*)header_base_entry;
if(header_db_entry->commit_ts_ < UNCOMMIT_TS) {
// Committed
if(header_db_entry->Committed()) {
if(begin_ts > header_db_entry->commit_ts_) {
// No conflict
if(header_db_entry->deleted_) {
Expand Down Expand Up @@ -193,7 +192,7 @@ DBMeta::DeleteNewEntry(DBMeta* db_meta, u64 txn_id, TxnManager* txn_mgr) {

auto removed_iter = std::remove_if(db_meta->entry_list_.begin(),
db_meta->entry_list_.end(),
[&](UniquePtr<BaseEntry>& entry)->bool {
[&](auto& entry)->bool {
return entry->txn_id_ == txn_id;
});

Expand All @@ -215,8 +214,7 @@ DBMeta::GetEntry(DBMeta* db_meta, u64 txn_id, TxnTimeStamp begin_ts) {
return {nullptr, MakeUnique<String>("No valid db entry.")};
}

if(db_entry->commit_ts_ < UNCOMMIT_TS) {
// committed
if(db_entry->Committed()) {
if(begin_ts > db_entry->commit_ts_) {
if(db_entry->deleted_) {
LOG_TRACE("DB is dropped.")
Expand All @@ -226,12 +224,15 @@ DBMeta::GetEntry(DBMeta* db_meta, u64 txn_id, TxnTimeStamp begin_ts) {
}
}
} else {
// Only committed txn is visible. Committing txn isn't visble.

// not committed, but the same txn is also visible
if(txn_id == db_entry->txn_id_) {
// same txn
return {db_entry.get(), nullptr};
// Only committed txn is visible. Committing txn isn't visble,
// except same txn is visible
if(txn_id == db_entry->txn_id_ ) {
if (db_entry->deleted_) {
LOG_TRACE("DB is dropped.")
return {nullptr, MakeUnique<String>("DB is dropped.")};
} else {
return {db_entry.get(), nullptr};
}
}
}
}
Expand Down
15 changes: 15 additions & 0 deletions src/storage/meta/entry/base_entry.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,21 @@ struct BaseEntry {
struct EntryResult {
BaseEntry* entry_;
UniquePtr<String> err_;

bool Success() {
return err_ == nullptr;
}

bool Fail() {
return err_ != nullptr;
}

String ToString() {
if(err_ == nullptr) {
return "Success";
}
return *err_.get();
}
};

}
5 changes: 5 additions & 0 deletions src/storage/txn/txn.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,11 @@ class Txn {
return txn_context_.GetCommitTS();
}

inline TxnTimeStamp
BeginTS() {
return txn_context_.GetBeginTS();
}

inline TxnState
GetTxnState() {
return txn_context_.GetTxnState();
Expand Down
Loading