Browse Source

fix compilation error

pull/991/head
Chris Lu 6 years ago
parent
commit
cd45ab072a
  1. 27
      weed/pb/filer_pb/filer_pb_helper.go
  2. 2
      weed/pb/filer_pb/filer_pb_helper_test.go
  3. 2
      weed/shell/command_volume_fix_replication.go

27
weed/pb/filer_pb/filer_pb_helper.go

@ -4,7 +4,7 @@ import (
"github.com/chrislusf/seaweedfs/weed/storage/needle" "github.com/chrislusf/seaweedfs/weed/storage/needle"
) )
func toFileId(fileIdStr string) (*FileId, error) {
func toFileIdObject(fileIdStr string) (*FileId, error) {
t, err := needle.ParseFileIdFromString(fileIdStr) t, err := needle.ParseFileIdFromString(fileIdStr)
if err != nil { if err != nil {
return nil, err return nil, err
@ -17,33 +17,44 @@ func toFileId(fileIdStr string) (*FileId, error) {
} }
func (fid *FileId) toFileId() string {
func (fid *FileId) toFileIdString() string {
return needle.NewFileId(needle.VolumeId(fid.VolumeId), fid.FileKey, fid.Cookie).String() return needle.NewFileId(needle.VolumeId(fid.VolumeId), fid.FileKey, fid.Cookie).String()
} }
func ChunkEquals(this, that *FileChunk) bool { func ChunkEquals(this, that *FileChunk) bool {
if this.Fid == nil{ if this.Fid == nil{
this.Fid, _ = toFileId(this.FileId)
this.Fid, _ = toFileIdObject(this.FileId)
} }
if that.Fid == nil{ if that.Fid == nil{
that.Fid, _ = toFileId(that.FileId)
that.Fid, _ = toFileIdObject(that.FileId)
} }
return this.Fid.FileKey == that.Fid.FileKey && this.Fid.VolumeId == that.Fid.VolumeId && this.Fid.Cookie == that.Fid.Cookie return this.Fid.FileKey == that.Fid.FileKey && this.Fid.VolumeId == that.Fid.VolumeId && this.Fid.Cookie == that.Fid.Cookie
} }
func (c *FileChunk) GetFileIdString() string {
if c.FileId != "" {
return c.FileId
}
if c.Fid != nil {
c.FileId = c.Fid.toFileIdString()
return c.FileId
}
return ""
}
func BeforeEntrySerialization(chunks []*FileChunk) { func BeforeEntrySerialization(chunks []*FileChunk) {
for _, chunk := range chunks { for _, chunk := range chunks {
if chunk.FileId != "" { if chunk.FileId != "" {
if fid, err := toFileId(chunk.FileId); err == nil {
if fid, err := toFileIdObject(chunk.FileId); err == nil {
chunk.Fid = fid chunk.Fid = fid
chunk.FileId = "" chunk.FileId = ""
} }
} }
if chunk.SourceFileId != "" { if chunk.SourceFileId != "" {
if fid, err := toFileId(chunk.SourceFileId); err == nil {
if fid, err := toFileIdObject(chunk.SourceFileId); err == nil {
chunk.SourceFid = fid chunk.SourceFid = fid
chunk.SourceFileId = "" chunk.SourceFileId = ""
} }
@ -57,11 +68,11 @@ func AfterEntryDeserialization(chunks []*FileChunk) {
for _, chunk := range chunks { for _, chunk := range chunks {
if chunk.Fid != nil && chunk.FileId == "" { if chunk.Fid != nil && chunk.FileId == "" {
chunk.FileId = chunk.Fid.toFileId()
chunk.FileId = chunk.Fid.toFileIdString()
} }
if chunk.SourceFid != nil && chunk.SourceFileId == "" { if chunk.SourceFid != nil && chunk.SourceFileId == "" {
chunk.SourceFileId = chunk.SourceFid.toFileId()
chunk.SourceFileId = chunk.SourceFid.toFileIdString()
} }
} }

2
weed/pb/filer_pb/filer_pb_helper_test.go

@ -9,7 +9,7 @@ import (
func TestFileIdSize(t *testing.T) { func TestFileIdSize(t *testing.T) {
fileIdStr := "11745,0293434534cbb9892b" fileIdStr := "11745,0293434534cbb9892b"
fid, _ := toFileId(fileIdStr)
fid, _ := toFileIdObject(fileIdStr)
bytes, _ := proto.Marshal(fid) bytes, _ := proto.Marshal(fid)
println(len(fileIdStr)) println(len(fileIdStr))

2
weed/shell/command_volume_fix_replication.go

@ -64,7 +64,7 @@ func (c *commandVolumeFixReplication) Do(args []string, commandEnv *CommandEnv,
replicatedVolumeInfo := make(map[uint32]*master_pb.VolumeInformationMessage) replicatedVolumeInfo := make(map[uint32]*master_pb.VolumeInformationMessage)
var allLocations []location var allLocations []location
eachDataNode(resp.TopologyInfo, func(dc string, rack RackId, dn *master_pb.DataNodeInfo) { eachDataNode(resp.TopologyInfo, func(dc string, rack RackId, dn *master_pb.DataNodeInfo) {
loc := newLocation(dc.Id, rack.Id, dn)
loc := newLocation(dc, string(rack), dn)
for _, v := range dn.VolumeInfos { for _, v := range dn.VolumeInfos {
if v.ReplicaPlacement > 0 { if v.ReplicaPlacement > 0 {
replicatedVolumeLocations[v.Id] = append(replicatedVolumeLocations[v.Id], loc) replicatedVolumeLocations[v.Id] = append(replicatedVolumeLocations[v.Id], loc)

Loading…
Cancel
Save