func (s *Server) createShardReplication(sri *topo.ShardReplicationInfo) (int64, error) { cell, err := s.getCell(sri.Cell()) if err != nil { return -1, err } data := jscfg.ToJSON(sri.ShardReplication) resp, err := cell.Create(shardReplicationFilePath(sri.Keyspace(), sri.Shard()), data, 0 /* ttl */) if err != nil { return -1, convertError(err) } if resp.Node == nil { return -1, ErrBadResponse } return int64(resp.Node.ModifiedIndex), nil }
func (s *Server) updateShardReplication(sri *topo.ShardReplicationInfo, existingVersion int64) (int64, error) { cell, err := s.getCell(sri.Cell()) if err != nil { return -1, err } data := jscfg.ToJSON(sri.ShardReplication) resp, err := cell.CompareAndSwap(shardReplicationFilePath(sri.Keyspace(), sri.Shard()), data, 0 /* ttl */, "" /* prevValue */, uint64(existingVersion)) if err != nil { return -1, convertError(err) } if resp.Node == nil { return -1, ErrBadResponse } return int64(resp.Node.ModifiedIndex), nil }