Added function to derive shard name for SrvShard.

This commit is contained in:
shrutip 2014-01-21 23:47:11 -08:00
Родитель 4d66eaf0e4
Коммит 0a767f58ab
1 изменённых файлов: 12 добавлений и 0 удалений

Просмотреть файл

@ -6,6 +6,7 @@ package topo
import (
"bytes"
"fmt"
"sort"
"github.com/youtube/vitess/go/bson"
@ -13,6 +14,10 @@ import (
"github.com/youtube/vitess/go/vt/key"
)
// This is the shard name for when the keyrange covers the entire space
// for unsharded database.
const SHARD_ZERO = "0"
// SrvShard contains a roll-up of the shard in the local namespace.
// In zk, it is under /zk/local/vt/ns/<keyspace>/<shard>
type SrvShard struct {
@ -120,6 +125,13 @@ func (ss *SrvShard) UnmarshalBson(buf *bytes.Buffer) {
}
}
func (ss *SrvShard) ShardName() string {
if !ss.KeyRange.IsPartial() {
return SHARD_ZERO
}
return fmt.Sprintf("%v-%v", ss.KeyRange.Start, ss.KeyRange.End)
}
// KeyspacePartition represents a continuous set of shards to
// serve an entire data set.
type KeyspacePartition struct {