Esempio n. 1
0
func NewShard(db storage.Engine, pointBatchSize, writeBatchSize int) (*Shard, error) {
	lastIdBytes, err2 := db.Get(NEXT_ID_KEY)
	if err2 != nil {
		return nil, err2
	}

	lastId := uint64(0)
	if lastIdBytes != nil {
		lastId, err2 = binary.ReadUvarint(bytes.NewBuffer(lastIdBytes))
		if err2 != nil {
			return nil, err2
		}
	}

	return &Shard{
		db:             db,
		lastIdUsed:     lastId,
		pointBatchSize: pointBatchSize,
		writeBatchSize: writeBatchSize,
	}, nil
}