Skip to content

Commit

Permalink
Fix transaction in UpdateAndFindMinSyncedVersionVector (#1050)
Browse files Browse the repository at this point in the history
This commit resolves an issue where the PushPull operation does not
function correctly when using the Memory DB.

UpdateAndFindMinSyncedVersionVector was previously set to start in
write mode, which causes it to simply read documents. However, inside
this function, it calls UpdateVersionVector, which attempts to start
in write mode again, resulting in a deadlock scenario where the
transaction cannot be acquired, causing an infinite wait.
  • Loading branch information
hackerwins authored Oct 25, 2024
1 parent bd2ebe9 commit fac4779
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions server/backend/database/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,9 +271,9 @@ type Database interface {
serverSeq int64,
) (*time.Ticket, error)

// UpdateAndFindMinSyncedVersionVectorAfterPushPull updates the given serverSeq of the given client
// UpdateAndFindMinSyncedVersionVector updates the given serverSeq of the given client
// and returns the SyncedVersionVector of the document.
UpdateAndFindMinSyncedVersionVectorAfterPushPull(
UpdateAndFindMinSyncedVersionVector(
ctx context.Context,
clientInfo *ClientInfo,
docRefKey types.DocRefKey,
Expand Down
6 changes: 3 additions & 3 deletions server/backend/database/memory/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -1312,9 +1312,9 @@ func (d *DB) UpdateVersionVector(
return nil
}

// UpdateAndFindMinSyncedVersionVectorAfterPushPull updates the given serverSeq of the given client
// UpdateAndFindMinSyncedVersionVector updates the given serverSeq of the given client
// and returns the SyncedVersionVector of the document.
func (d *DB) UpdateAndFindMinSyncedVersionVectorAfterPushPull(
func (d *DB) UpdateAndFindMinSyncedVersionVector(
ctx context.Context,
clientInfo *database.ClientInfo,
docRefKey types.DocRefKey,
Expand All @@ -1338,7 +1338,7 @@ func (d *DB) UpdateAndFindMinSyncedVersionVectorAfterPushPull(
}

// 02. Find all version vectors of the given document from DB.
txn := d.db.Txn(true)
txn := d.db.Txn(false)
defer txn.Abort()
iterator, err := txn.Get(tblVersionVectors, "doc_id", docRefKey.DocID.String())
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions server/backend/database/mongo/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -1197,8 +1197,8 @@ func (c *Client) UpdateAndFindMinSyncedTicket(
), nil
}

// UpdateAndFindMinSyncedVersionVectorAfterPushPull returns min synced version vector
func (c *Client) UpdateAndFindMinSyncedVersionVectorAfterPushPull(
// UpdateAndFindMinSyncedVersionVector returns min synced version vector
func (c *Client) UpdateAndFindMinSyncedVersionVector(
ctx context.Context,
clientInfo *database.ClientInfo,
docRefKey types.DocRefKey,
Expand Down
2 changes: 1 addition & 1 deletion server/packs/packs.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ func PushPull(
// 05. update and find min synced version vector for garbage collection.
// NOTE(hackerwins): Since the client could not receive the response, the
// requested seq(reqPack) is stored instead of the response seq(resPack).
minSyncedVersionVector, err := be.DB.UpdateAndFindMinSyncedVersionVectorAfterPushPull(
minSyncedVersionVector, err := be.DB.UpdateAndFindMinSyncedVersionVector(
ctx,
clientInfo,
docRefKey,
Expand Down

0 comments on commit fac4779

Please sign in to comment.