Skip to content

Commit 3228c04

Browse files
committed
feat(treansaction): Use single hop in squashing when possible
Signed-off-by: Vladislav Oleshko <[email protected]>
1 parent 90a9f05 commit 3228c04

File tree

10 files changed

+263
-218
lines changed

10 files changed

+263
-218
lines changed

src/server/command_registry.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,10 @@ class CommandId : public facade::CommandId {
9393

9494
bool IsTransactional() const;
9595

96+
bool IsMultiTransactional() const {
97+
return CO::IsTransKind(name()) || CO::IsEvalKind(name());
98+
}
99+
96100
bool IsReadOnly() const {
97101
return opt_mask_ & CO::READONLY;
98102
}

src/server/conn_context.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ ConnectionContext::ConnectionContext(const ConnectionContext* owner, Transaction
9393
if (tx) { // If we have a carrier transaction, this context is used for squashing
9494
DCHECK(owner);
9595
conn_state.db_index = owner->conn_state.db_index;
96-
conn_state.squashing_info = {owner};
96+
conn_state.squashing_info = {owner, owner->transaction};
9797
}
9898
auto* prev_reply_builder = Inject(crb);
9999
CHECK_EQ(prev_reply_builder, nullptr);
@@ -234,7 +234,7 @@ size_t ConnectionState::ExecInfo::UsedMemory() const {
234234
}
235235

236236
size_t ConnectionState::ScriptInfo::UsedMemory() const {
237-
return dfly::HeapSize(keys) + async_cmds_heap_mem;
237+
return async_cmds_heap_mem;
238238
}
239239

240240
size_t ConnectionState::SubscribeInfo::UsedMemory() const {

src/server/conn_context.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,6 @@ struct ConnectionState {
101101
struct ScriptInfo {
102102
size_t UsedMemory() const;
103103

104-
absl::flat_hash_set<std::string_view> keys; // declared keys
105-
106104
size_t async_cmds_heap_mem = 0; // bytes used by async_cmds
107105
size_t async_cmds_heap_limit = 0; // max bytes allowed for async_cmds
108106
std::vector<StoredCmd> async_cmds; // aggregated by acall
@@ -135,10 +133,11 @@ struct ConnectionState {
135133
};
136134

137135
struct SquashingInfo {
138-
// Pointer to the original underlying context of the base command.
139-
// Only const access it possible for reading from multiple threads,
140-
// each squashing thread has its own proxy context that contains this info.
136+
// Underlying context of the base command, should be used for state checks.
137+
// Note: some squashing mechanisms re-use the context (single shard eval).
141138
const ConnectionContext* owner = nullptr;
139+
// Underlying base transaction of squashing mechanism.
140+
const Transaction* transaction = nullptr;
142141
};
143142

144143
enum MCGetMask {

src/server/journal/tx_executor.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ std::optional<TransactionData> TransactionReader::NextTxData(JournalReader* read
117117

118118
// Otherwise, continue building multi command.
119119
DCHECK(res->opcode == journal::Op::MULTI_COMMAND || res->opcode == journal::Op::EXEC);
120-
DCHECK(res->txid > 0);
120+
// DCHECK(res->txid > 0);
121121

122122
auto txid = res->txid;
123123
auto& txdata = current_[txid];

0 commit comments

Comments
 (0)