Skip to content

Commit

Permalink
chore: rename to Baton
Browse files Browse the repository at this point in the history
  • Loading branch information
dranikpg committed Feb 1, 2024
1 parent f8a8e76 commit 62f804a
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 6 deletions.
22 changes: 22 additions & 0 deletions src/core/interpreter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <absl/time/clock.h>
#include <mimalloc.h>
#include <openssl/evp.h>
#include <xxhash.h>

#include <cstring>
#include <optional>
Expand Down Expand Up @@ -323,6 +324,23 @@ int RedisSha1Command(lua_State* lua) {
return 1;
}

int RedisIHashCommand(lua_State* lua) {
int argc = lua_gettop(lua);
if (argc != 1) {
lua_pushstring(lua, "wrong number of arguments");
return lua_error(lua);
}

size_t len;
const char* s = lua_tolstring(lua, 1, &len);

size_t hash = XXH64(s, len, 120577240643ULL);
// lua_Integer lua_hash = absl::

lua_pushinteger(lua, hash);
return 1;
}

/* Returns a table with a single field 'field' set to the string value
* passed as argument. This helper function is handy when returning
* a Redis Protocol error or status reply from Lua:
Expand Down Expand Up @@ -414,6 +432,10 @@ Interpreter::Interpreter() {
lua_pushcfunction(lua_, RedisSha1Command);
lua_settable(lua_, -3);

lua_pushstring(lua_, "ihash");
lua_pushcfunction(lua_, RedisIHashCommand);
lua_settable(lua_, -3);

/* redis.error_reply and redis.status_reply */
lua_pushstring(lua_, "error_reply");
lua_pushcfunction(lua_, RedisErrorReplyCommand);
Expand Down
8 changes: 4 additions & 4 deletions src/server/transaction.cc
Original file line number Diff line number Diff line change
Expand Up @@ -124,21 +124,21 @@ uint32_t Transaction::PhasedBarrier::DEBUG_Count() const {
return count_.load(memory_order_relaxed);
}

bool Transaction::SingleClaimBarrier::IsClaimed() const {
bool Transaction::BatonBarrierrier::IsClaimed() const {
return claimed_.load(memory_order_relaxed);
}

bool Transaction::SingleClaimBarrier::TryClaim() {
bool Transaction::BatonBarrierrier::TryClaim() {
return !claimed_.exchange(true, memory_order_relaxed); // false means first means success
}

void Transaction::SingleClaimBarrier::Close() {
void Transaction::BatonBarrierrier::Close() {
DCHECK(claimed_.load(memory_order_relaxed));
closed_.store(true, memory_order_relaxed);
ec_.notify(); // release
}

cv_status Transaction::SingleClaimBarrier::Wait(time_point tp) {
cv_status Transaction::BatonBarrierrier::Wait(time_point tp) {
auto cb = [this] { return closed_.load(memory_order_acquire); };

if (tp != time_point::max()) {
Expand Down
4 changes: 2 additions & 2 deletions src/server/transaction.h
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ class Transaction {
// "Single claim - single modification" barrier. Multiple threads might try to claim it, only one
// will succeed and will be allowed to modify the guarded object until it closes the barrier.
// A closed barrier can't be claimed again or re-used in any way.
class SingleClaimBarrier {
class BatonBarrierrier {
public:
bool IsClaimed() const; // Return if barrier is claimed, only for peeking
bool TryClaim(); // Return if the barrier was claimed successfully
Expand Down Expand Up @@ -611,7 +611,7 @@ class Transaction {
UniqueSlotChecker unique_slot_checker_;

// Barrier for waking blocking transactions that ensures exclusivity of waking operation.
SingleClaimBarrier blocking_barrier_{};
BatonBarrierrier blocking_barrier_{};

// Transaction coordinator state, written and read by coordinator thread.
uint8_t coordinator_state_ = 0;
Expand Down

0 comments on commit 62f804a

Please sign in to comment.