Skip to content

Commit

Permalink
dragonboat: updated IStateMachine's Update() API
Browse files Browse the repository at this point in the history
  • Loading branch information
lni committed Jun 4, 2022
1 parent 3d77ec5 commit d5927d0
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 18 deletions.
2 changes: 1 addition & 1 deletion internal/rsm/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func (i *InMemStateMachine) Update(entries []sm.Entry) ([]sm.Entry, error) {
panic("len(entries) != 1")
}
var err error
entries[0].Result, err = i.sm.Update(entries[0].Cmd)
entries[0].Result, err = i.sm.Update(entries[0])
return entries, errors.WithStack(err)
}

Expand Down
2 changes: 1 addition & 1 deletion internal/rsm/statemachine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2622,7 +2622,7 @@ func expectedError(err error) bool {

type errorUpdateSM struct{}

func (e *errorUpdateSM) Update(data []byte) (sm.Result, error) {
func (e *errorUpdateSM) Update(i sm.Entry) (sm.Result, error) {
return sm.Result{}, errReturnedError
}
func (e *errorUpdateSM) Lookup(q interface{}) (interface{}, error) { return nil, nil }
Expand Down
4 changes: 2 additions & 2 deletions internal/tests/concurrent.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ type TestUpdate struct {
}

// Update updates the state machine.
func (c *TestUpdate) Update(data []byte) (sm.Result, error) {
func (c *TestUpdate) Update(e sm.Entry) (sm.Result, error) {
atomic.StoreUint32(&c.val, 1)
for i := 0; i < 5; i++ {
time.Sleep(1 * time.Millisecond)
Expand Down Expand Up @@ -134,7 +134,7 @@ type TestSnapshot struct {
}

// Update updates the state machine.
func (c *TestSnapshot) Update(data []byte) (sm.Result, error) {
func (c *TestSnapshot) Update(e sm.Entry) (sm.Result, error) {
return sm.Result{Value: uint64(atomic.LoadUint32(&c.val))}, nil
}

Expand Down
8 changes: 4 additions & 4 deletions internal/tests/kvtest.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ func (s *KVTest) Lookup(key interface{}) (interface{}, error) {
}

// Update updates the object using the specified committed raft entry.
func (s *KVTest) Update(data []byte) (sm.Result, error) {
func (s *KVTest) Update(e sm.Entry) (sm.Result, error) {
s.Count++
if s.aborted {
panic("update() called after abort set to true")
Expand All @@ -152,13 +152,13 @@ func (s *KVTest) Update(data []byte) (sm.Result, error) {
}
generateRandomDelay()
dataKv := s.pbkvPool.Get().(*kvpb.PBKV)
err := dataKv.Unmarshal(data)
err := dataKv.Unmarshal(e.Cmd)
if err != nil {
panic(err)
}
s.updateStore(dataKv.GetKey(), dataKv.GetVal())
s.pbkvPool.Put(dataKv)
return sm.Result{Value: uint64(len(data))}, nil
return sm.Result{Value: uint64(len(e.Cmd))}, nil
}

func (s *KVTest) saveExternalFile(fileCollection sm.ISnapshotFileCollection) {
Expand Down Expand Up @@ -318,7 +318,7 @@ type VerboseSnapshotSM struct {
}

// Update ...
func (v *VerboseSnapshotSM) Update(data []byte) (sm.Result, error) {
func (v *VerboseSnapshotSM) Update(e sm.Entry) (sm.Result, error) {
return sm.Result{}, nil
}

Expand Down
10 changes: 5 additions & 5 deletions internal/tests/noop.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,17 @@ func (n *NoOP) NALookup(key []byte) ([]byte, error) {
}

// Update updates the object.
func (n *NoOP) Update(data []byte) (sm.Result, error) {
func (n *NoOP) Update(e sm.Entry) (sm.Result, error) {
sleep := atomic.LoadUint64(&n.MillisecondToSleep)
if sleep > 0 {
time.Sleep(time.Duration(sleep) * time.Millisecond)
}
if n.NoAlloc {
return sm.Result{Value: uint64(len(data))}, nil
return sm.Result{Value: uint64(len(e.Cmd))}, nil
}
v := make([]byte, len(data))
copy(v, data)
return sm.Result{Value: uint64(len(data)), Data: v}, nil
v := make([]byte, len(e.Cmd))
copy(v, e.Cmd)
return sm.Result{Value: uint64(len(e.Cmd)), Data: v}, nil
}

// SaveSnapshot saves the state of the object to the provided io.Writer object.
Expand Down
8 changes: 4 additions & 4 deletions nodehost_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ type TimeoutStateMachine struct {
closed bool
}

func (t *TimeoutStateMachine) Update(date []byte) (sm.Result, error) {
func (t *TimeoutStateMachine) Update(e sm.Entry) (sm.Result, error) {
if t.updateDelay > 0 {
time.Sleep(time.Duration(t.updateDelay) * time.Millisecond)
}
Expand Down Expand Up @@ -1229,8 +1229,8 @@ func (n *PST) Lookup(key interface{}) (interface{}, error) {
}

// Update updates the object.
func (n *PST) Update(data []byte) (sm.Result, error) {
return sm.Result{Value: uint64(len(data))}, nil
func (n *PST) Update(e sm.Entry) (sm.Result, error) {
return sm.Result{Value: uint64(len(e.Cmd))}, nil
}

// SaveSnapshot saves the state of the object to the provided io.Writer object.
Expand Down Expand Up @@ -5729,7 +5729,7 @@ func TestBootstrapInfoIsValidated(t *testing.T) {

type stressRSM struct{}

func (s *stressRSM) Update([]byte) (sm.Result, error) {
func (s *stressRSM) Update(sm.Entry) (sm.Result, error) {
plog.Infof("updated")
return sm.Result{}, nil
}
Expand Down
2 changes: 1 addition & 1 deletion statemachine/rsm.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ type IStateMachine interface {
// Update returns a Result value used to indicate the outcome of the update
// operation. An error is returned when there is unrecoverable error, such
// error will cause the program to panic.
Update([]byte) (Result, error)
Update(Entry) (Result, error)
// Lookup queries the state of the IStateMachine instance. The input
// interface{} specifies what to query, it is up to the IStateMachine
// implementation to interpret such input interface{}. The returned
Expand Down

0 comments on commit d5927d0

Please sign in to comment.