Skip to content

Commit 7db9a7c

Browse files
committed
Check partition count before updating routing table
1 parent d5f5de6 commit 7db9a7c

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

cmd/olricd/server/server.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,6 @@ func New(c *Config) (*Olricd, error) {
153153

154154
s.log = log.New(logOutput, "", log.LstdFlags)
155155
s.config = &config.Config{
156-
Name: c.Olricd.Name, // deprecated, it will be removed in v0.3.0
157156
BindAddr: c.Olricd.BindAddr,
158157
BindPort: c.Olricd.BindPort,
159158
Interface: c.Olricd.Interface,

olric.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ var (
5555

5656
// ErrUnknownOperation means that an unidentified message has been received from a client.
5757
ErrUnknownOperation = errors.New("unknown operation")
58+
59+
// ErrBadRequest denotes that request body is invalid.
60+
ErrBadRequest = errors.New("bad request")
5861
)
5962

6063
// ReleaseVersion is the current stable version of Olric
@@ -447,6 +450,8 @@ func (db *Olric) prepareResponse(req *protocol.Message, err error) *protocol.Mes
447450
return req.Error(protocol.StatusErrUnknownOperation, err)
448451
case err == ErrEndOfQuery:
449452
return req.Error(protocol.StatusErrEndOfQuery, err)
453+
case err == ErrBadRequest:
454+
return req.Error(protocol.StatusBadRequest, err)
450455
default:
451456
return req.Error(protocol.StatusInternalServerError, err)
452457
}
@@ -483,6 +488,8 @@ func (db *Olric) requestTo(addr string, opcode protocol.OpCode, req *protocol.Me
483488
return nil, ErrEndOfQuery
484489
case resp.Status == protocol.StatusErrUnknownOperation:
485490
return nil, ErrUnknownOperation
491+
case resp.Status == protocol.StatusBadRequest:
492+
return nil, ErrBadRequest
486493
}
487494
return nil, fmt.Errorf("unknown status code: %d", resp.Status)
488495
}

routing.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,14 @@ func (db *Olric) updateRoutingOperation(req *protocol.Message) *protocol.Message
444444
coordinator, err := db.checkAndGetCoordinator(coordinatorID)
445445
if err != nil {
446446
db.log.V(2).Printf("[ERROR] Routing table cannot be updated: %v", err)
447-
return req.Error(protocol.StatusInternalServerError, err)
447+
return req.Error(protocol.StatusBadRequest, err)
448+
}
449+
450+
// Compare partition counts to catch a possible inconsistencies in configuration
451+
if db.config.PartitionCount != uint64(len(table)) {
452+
db.log.V(2).Printf("[ERROR] Routing table cannot be updated. " +
453+
"Expected partition count is %d, got: %d", db.config.PartitionCount, uint64(len(table)))
454+
return req.Error(protocol.StatusBadRequest, err)
448455
}
449456

450457
// owners(atomic.Value) is guarded by routingUpdateMtx against parallel writers.

0 commit comments

Comments
 (0)