Skip to content

Commit

Permalink
Fixed create and modified timestamps not getting set (#431)
Browse files Browse the repository at this point in the history
After #363, the timestamps were always getting set to 0
  • Loading branch information
merlimat authored Jan 22, 2024
1 parent ab77820 commit 8862ffc
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 12 deletions.
16 changes: 8 additions & 8 deletions oxia/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ func Example() {
// Sleep to avoid DATA RACE on zerolog read at os.Stdout,and runExamples write at os.Stdout
time.Sleep(2 * time.Second)

fmt.Printf("Result: %s - %#v\n", string(value), version)
// Output: Result: value-2 - oxia.Version{VersionId:1, CreatedTimestamp:0x0, ModifiedTimestamp:0x0, ModificationsCount:1, Ephemeral:false, ClientIdentity:""}
fmt.Printf("Result: %s - Version: %#v\n", string(value), version.VersionId)
// Output: Result: value-2 - Version: 1
}

func ExampleAsyncClient() {
Expand All @@ -103,22 +103,22 @@ func ExampleAsyncClient() {

// Wait for the async operations to complete
r1 := <-c1
fmt.Printf("First operation complete: version: %#v - error: %#v\n", r1.Version, r1.Err)
fmt.Printf("First operation complete: version: %#v - error: %#v\n", r1.Version.VersionId, r1.Err)

r2 := <-c2
fmt.Printf("First operation complete: version: %#v - error: %#v\n", r2.Version, r2.Err)
fmt.Printf("First operation complete: version: %#v - error: %#v\n", r2.Version.VersionId, r2.Err)

r3 := <-c3
fmt.Printf("First operation complete: version: %#v - error: %#v\n", r3.Version, r3.Err)
fmt.Printf("First operation complete: version: %#v - error: %#v\n", r3.Version.VersionId, r3.Err)

_ = client.Close()
// Sleep to avoid DATA RACE on zerolog read at os.Stdout,and runExamples write at os.Stdout
time.Sleep(2 * time.Second)

// Output:
// First operation complete: version: oxia.Version{VersionId:0, CreatedTimestamp:0x0, ModifiedTimestamp:0x0, ModificationsCount:0, Ephemeral:false, ClientIdentity:""} - error: <nil>
// First operation complete: version: oxia.Version{VersionId:0, CreatedTimestamp:0x0, ModifiedTimestamp:0x0, ModificationsCount:0, Ephemeral:false, ClientIdentity:""} - error: <nil>
// First operation complete: version: oxia.Version{VersionId:0, CreatedTimestamp:0x0, ModifiedTimestamp:0x0, ModificationsCount:0, Ephemeral:false, ClientIdentity:""} - error: <nil>
// First operation complete: version: 0 - error: <nil>
// First operation complete: version: 0 - error: <nil>
// First operation complete: version: 0 - error: <nil>
}

func ExampleNotifications() {
Expand Down
9 changes: 5 additions & 4 deletions server/leader_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ package server
import (
"context"
"fmt"
"io"
"log/slog"
"sync"

"github.com/pkg/errors"
"go.uber.org/multierr"
pb "google.golang.org/protobuf/proto"
"io"
"log/slog"
"sync"
"time"

"github.com/streamnative/oxia/common"
"github.com/streamnative/oxia/common/metrics"
Expand Down Expand Up @@ -715,6 +715,7 @@ func (lc *leaderController) appendToWal(ctx context.Context, request func(int64)
}

newOffset := lc.quorumAckTracker.NextOffset()
timestamp = uint64(time.Now().UnixMilli())
actualRequest = request(newOffset)

lc.log.Debug(
Expand Down
3 changes: 3 additions & 0 deletions server/leader_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,9 @@ func TestLeaderController_BecomeLeader_RF1(t *testing.T) {
assert.EqualValues(t, 1, len(res.Puts))
assert.Equal(t, proto.Status_OK, res.Puts[0].Status)
assert.EqualValues(t, 0, res.Puts[0].Version.VersionId)
assert.NotEqualValues(t, 0, res.Puts[0].Version.CreatedTimestamp)
assert.NotEqualValues(t, 0, res.Puts[0].Version.ModifiedTimestamp)
assert.EqualValues(t, res.Puts[0].Version.CreatedTimestamp, res.Puts[0].Version.ModifiedTimestamp)

// Read entry
r := <-lc.Read(context.Background(), &proto.ReadRequest{
Expand Down

0 comments on commit 8862ffc

Please sign in to comment.