diff --git a/oxia/example_test.go b/oxia/example_test.go index 96cfe1c7..0f934f16 100644 --- a/oxia/example_test.go +++ b/oxia/example_test.go @@ -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() { @@ -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: - // First operation complete: version: oxia.Version{VersionId:0, CreatedTimestamp:0x0, ModifiedTimestamp:0x0, ModificationsCount:0, Ephemeral:false, ClientIdentity:""} - error: - // First operation complete: version: oxia.Version{VersionId:0, CreatedTimestamp:0x0, ModifiedTimestamp:0x0, ModificationsCount:0, Ephemeral:false, ClientIdentity:""} - error: + // First operation complete: version: 0 - error: + // First operation complete: version: 0 - error: + // First operation complete: version: 0 - error: } func ExampleNotifications() { diff --git a/server/leader_controller.go b/server/leader_controller.go index 066fd496..ccf3a33c 100644 --- a/server/leader_controller.go +++ b/server/leader_controller.go @@ -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" @@ -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( diff --git a/server/leader_controller_test.go b/server/leader_controller_test.go index b2b2dc69..cc0f4a20 100644 --- a/server/leader_controller_test.go +++ b/server/leader_controller_test.go @@ -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{