Skip to content

Commit

Permalink
fix: improve logging
Browse files Browse the repository at this point in the history
  • Loading branch information
thawk105 committed Feb 6, 2024
1 parent 17534d5 commit 2dd56b4
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 25 deletions.
2 changes: 1 addition & 1 deletion src/concurrency_control/interface/storage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ Status get_storage(std::string_view key, Storage& out) {
shirakami_log_entry << "get_storage " << shirakami_binstring(key)
<< ", out: " << out;
auto ret = get_storage_body(key, out);
shirakami_log_exit << "get_storage, " << ret;
shirakami_log_exit << "get_storage, " << ret << ", " << out;
return ret;
}

Expand Down
55 changes: 31 additions & 24 deletions src/concurrency_control/sequence.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ namespace shirakami {
Status create_sequence(SequenceId* const id) {
shirakami_log_entry << "create_sequence, id: " << id;
auto ret = sequence::create_sequence(id);
shirakami_log_exit << "create_sequence";
shirakami_log_exit << "create_sequence, " << ret << ", " << *id;
return ret;
}

Expand All @@ -38,9 +38,10 @@ Status update_sequence(Token const token, SequenceId const id, // NOLINT
Status read_sequence(SequenceId const id, SequenceVersion* const version,
SequenceValue* const value) {
shirakami_log_entry << "read_sequence, id: " << id
<< ", version: " << version << ", value: " << value;
<< ", version: " << *version << ", value: " << *value;
auto ret = sequence::read_sequence(id, version, value);
shirakami_log_exit << "read_sequence, " << ret;
shirakami_log_exit << "read_sequence, " << ret << ", " << *version << ", "
<< *value;
return ret;
}

Expand Down Expand Up @@ -153,9 +154,10 @@ Status sequence::sequence_map_push(SequenceId const id,
std::make_pair(epoch, std::make_tuple(version, value)));
if (!ret2.second) {
// This object must be operated by here.
LOG_FIRST_N(ERROR, 1) << log_location_prefix
<< "When it tried to manipulate an object inserted into "
"map, it was already manipulated by someone else.";
LOG_FIRST_N(ERROR, 1)
<< log_location_prefix
<< "When it tried to manipulate an object inserted into "
"map, it was already manipulated by someone else.";
// maybe lack of mutex control
return Status::ERR_FATAL;
}
Expand Down Expand Up @@ -270,8 +272,9 @@ Status sequence::create_sequence(SequenceId* id) {
// generate sequence object
ret = sequence::sequence_map_push(*id);
if (ret == Status::WARN_ALREADY_EXISTS) {
LOG_FIRST_N(ERROR, 1) << log_location_prefix
<< "Unexpected behavior. Id is already exist: " << *id;
LOG_FIRST_N(ERROR, 1)
<< log_location_prefix
<< "Unexpected behavior. Id is already exist: " << *id;
return Status::ERR_FATAL;
}

Expand All @@ -295,30 +298,32 @@ Status sequence::create_sequence(SequenceId* id) {
sizeof(initial_value));
ret = tx_begin({token, transaction_options::transaction_type::SHORT});
if (ret != Status::OK) {
LOG_FIRST_N(ERROR, 1) << log_location_prefix
<< "There is no way that short tx will fail to start here. "
<< ret;
LOG_FIRST_N(ERROR, 1)
<< log_location_prefix
<< "There is no way that short tx will fail to start here. "
<< ret;
}
ret = upsert(token, storage::sequence_storage, key, value);
if (ret != Status::OK) {
LOG_FIRST_N(ERROR, 1) << log_location_prefix
<< "There is no way that upsert will fail to start here: "
<< ret;
LOG_FIRST_N(ERROR, 1)
<< log_location_prefix
<< "There is no way that upsert will fail to start here: "
<< ret;
return Status::ERR_FATAL;
}
ret = commit(token);
if (ret != Status::OK) {
LOG_FIRST_N(ERROR, 1) << log_location_prefix
<< "There is no way that 1 upsert only"
"stx will fail here";
<< "There is no way that 1 upsert only"
"stx will fail here";
return Status::ERR_FATAL;
}

// cleanup transaction handle
ret = leave(token);
if (ret != Status::OK) {
LOG_FIRST_N(ERROR, 1) << log_location_prefix
<< "There is no way that leave will fail here";
<< "There is no way that leave will fail here";
return Status::ERR_FATAL;
}

Expand Down Expand Up @@ -404,36 +409,38 @@ Status sequence::delete_sequence(SequenceId const id) {
sizeof(value));
ret = tx_begin({token, transaction_options::transaction_type::SHORT});
if (ret != Status::OK) {
LOG_FIRST_N(ERROR, 1) << log_location_prefix
<< "there is no way stx begin will fail here. " << ret;
LOG_FIRST_N(ERROR, 1)
<< log_location_prefix
<< "there is no way stx begin will fail here. " << ret;
}
ret = upsert(token, storage::sequence_storage, key, new_value);
if (ret != Status::OK) {
LOG_FIRST_N(ERROR, 1) << log_location_prefix
<< "there is no way stx's upsert will fail here";
<< "there is no way stx's upsert will fail here";
return Status::ERR_FATAL;
}
ret = commit(token);
if (ret != Status::OK) {
LOG_FIRST_N(ERROR, 1) << log_location_prefix
<< "there is no way commit will fail here.";
<< "there is no way commit will fail here.";
return Status::ERR_FATAL;
}

// update sequence object to deleted
auto epoch = static_cast<session*>(token)->get_mrc_tid().get_epoch();
ret = sequence::sequence_map_update(id, epoch, version, value);
if (ret != Status::OK) {
LOG_FIRST_N(ERROR, 1) << log_location_prefix
<< "there is no way sequence map update will fail here.";
LOG_FIRST_N(ERROR, 1)
<< log_location_prefix
<< "there is no way sequence map update will fail here.";
return Status::ERR_FATAL;
}

// cleanup transaction handle
ret = leave(token);
if (ret != Status::OK) {
LOG_FIRST_N(ERROR, 1) << log_location_prefix
<< "there is no way leave will fail here.";
<< "there is no way leave will fail here.";
return Status::ERR_FATAL;
}

Expand Down

0 comments on commit 2dd56b4

Please sign in to comment.