Skip to content

Commit 52337a3

Browse files
committed
Add defaultTxnLockTTLSeconds constant and use it
1 parent 378c31c commit 52337a3

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

kv/coordinator.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,13 +121,16 @@ func (c *Coordinate) toRawRequest(req *Elem[OP]) *pb.Request {
121121
panic("unreachable")
122122
}
123123

124+
const defaultTxnLockTTLSeconds = uint64(30)
125+
124126
func (c *Coordinate) toTxnRequests(req *Elem[OP]) []*pb.Request {
125127
switch req.Op {
126128
case Put:
127129
return []*pb.Request{
128130
{
129131
IsTxn: true,
130132
Phase: pb.Phase_PREPARE,
133+
Ts: defaultTxnLockTTLSeconds,
131134
Mutations: []*pb.Mutation{
132135
{
133136
Key: req.Key,
@@ -138,6 +141,7 @@ func (c *Coordinate) toTxnRequests(req *Elem[OP]) []*pb.Request {
138141
{
139142
IsTxn: true,
140143
Phase: pb.Phase_COMMIT,
144+
Ts: defaultTxnLockTTLSeconds,
141145
Mutations: []*pb.Mutation{
142146
{
143147
Key: req.Key,
@@ -152,6 +156,7 @@ func (c *Coordinate) toTxnRequests(req *Elem[OP]) []*pb.Request {
152156
{
153157
IsTxn: true,
154158
Phase: pb.Phase_PREPARE,
159+
Ts: defaultTxnLockTTLSeconds,
155160
Mutations: []*pb.Mutation{
156161
{
157162
Key: req.Key,
@@ -161,6 +166,7 @@ func (c *Coordinate) toTxnRequests(req *Elem[OP]) []*pb.Request {
161166
{
162167
IsTxn: true,
163168
Phase: pb.Phase_COMMIT,
169+
Ts: defaultTxnLockTTLSeconds,
164170
Mutations: []*pb.Mutation{
165171
{
166172
Key: req.Key,

kv/fsm.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,13 @@ func (f *kvFSM) handleCommitRequest(ctx context.Context, r *pb.Request) error {
209209
}
210210

211211
if !ok {
212-
return errors.WithStack(ErrKeyNotLocked)
212+
// Lock missing (e.g., expired). Try to reacquire to make progress.
213+
err := f.lockStore.TxnWithTTL(ctx, func(ctx context.Context, ttlTxn store.TTLTxn) error {
214+
return f.lock(ttlTxn, mut.Key, r.Ts)
215+
})
216+
if err != nil {
217+
return errors.WithStack(err)
218+
}
213219
}
214220

215221
err = f.commit(ctx, txn, mut)

0 commit comments

Comments
 (0)