1
0
Fork 0

Noop() returns ApplyFuture

master
Philip O'Toole 9 months ago
parent 70b9bdbf84
commit cc4addf7e0

@ -1287,9 +1287,16 @@ func (s *Store) loadChunk(lcr *command.LoadChunkRequest) error {
// Send one last command through the log to deal with issues in
// underlying Raft code when truncating log to zero trailing.
if lcr.Abort || lcr.IsLast {
if err := s.Noop("load-chunk-trailing"); err != nil {
af, err = s.Noop("load-chunk-trailing")
if err != nil {
return err
}
if af.Error() != nil {
if af.Error() == raft.ErrNotLeader {
return ErrNotLeader
}
return af.Error()
}
}
s.dbAppliedIndexMu.Lock()
@ -1501,13 +1508,13 @@ func (s *Store) Remove(rn *command.RemoveNodeRequest) error {
// Noop writes a noop command to the Raft log. A noop command simply
// consumes a slot in the Raft log, but has no other effect on the
// system.
func (s *Store) Noop(id string) error {
func (s *Store) Noop(id string) (raft.ApplyFuture, error) {
n := &command.Noop{
Id: id,
}
b, err := command.MarshalNoop(n)
if err != nil {
return err
return nil, err
}
c := &command.Command{
@ -1516,17 +1523,10 @@ func (s *Store) Noop(id string) error {
}
bc, err := command.Marshal(c)
if err != nil {
return err
return nil, err
}
af := s.raft.Apply(bc, s.ApplyTimeout)
if af.Error() != nil {
if af.Error() == raft.ErrNotLeader {
return ErrNotLeader
}
return af.Error()
}
return nil
return s.raft.Apply(bc, s.ApplyTimeout), nil
}
// RequiresLeader returns whether the given ExecuteQueryRequest must be

@ -2856,9 +2856,13 @@ func Test_SingleNodeNoop(t *testing.T) {
t.Fatalf("Error waiting for leader: %s", err)
}
if err := s.Noop("1"); err != nil {
af, err := s.Noop("1")
if err != nil {
t.Fatalf("failed to write noop command: %s", err.Error())
}
if af.Error() != nil {
t.Fatalf("expected nil apply future error")
}
if s.numNoops != 1 {
t.Fatalf("noop count is wrong, got: %d", s.numNoops)
}

@ -194,7 +194,11 @@ func (n *Node) RequestMultiParameterized(stmt []interface{}) (string, error) {
// Noop inserts a noop command into the Store's Raft log.
func (n *Node) Noop(id string) error {
return n.Store.Noop(id)
af, err := n.Store.Noop(id)
if err != nil {
return err
}
return af.Error()
}
// EnableTLSClient enables TLS support for the node's cluster client.

Loading…
Cancel
Save