diff options
| author | Chris Lu <chris.lu@gmail.com> | 2013-04-16 00:10:21 -0700 |
|---|---|---|
| committer | Chris Lu <chris.lu@gmail.com> | 2013-04-16 00:10:21 -0700 |
| commit | 915b16f97a38affeaec6ced9860e1d30a903c047 (patch) | |
| tree | ff22485887c052e26f7d380435211ea17789c7af /go/storage | |
| parent | e4da140d0a565bda12ac4edc6786765e65343494 (diff) | |
| download | seaweedfs-915b16f97a38affeaec6ced9860e1d30a903c047.tar.xz seaweedfs-915b16f97a38affeaec6ced9860e1d30a903c047.zip | |
refactoring, same logic, but the store replication logic is moved to a
stand-alone file, for later easier improvements
Diffstat (limited to 'go/storage')
| -rw-r--r-- | go/storage/file_id.go | 37 | ||||
| -rw-r--r-- | go/storage/needle.go | 4 |
2 files changed, 39 insertions, 2 deletions
diff --git a/go/storage/file_id.go b/go/storage/file_id.go new file mode 100644 index 000000000..0fdee9f13 --- /dev/null +++ b/go/storage/file_id.go @@ -0,0 +1,37 @@ +package storage + +import ( + "code.google.com/p/weed-fs/go/util" + "encoding/hex" + "strings" +) + +type FileId struct { + VolumeId VolumeId + Key uint64 + Hashcode uint32 +} + +func NewFileId(VolumeId VolumeId, Key uint64, Hashcode uint32) *FileId { + return &FileId{VolumeId: VolumeId, Key: Key, Hashcode: Hashcode} +} +func ParseFileId(fid string) *FileId { + a := strings.Split(fid, ",") + if len(a) != 2 { + println("Invalid fid", fid, ", split length", len(a)) + return nil + } + vid_string, key_hash_string := a[0], a[1] + volumeId, _ := NewVolumeId(vid_string) + key, hash := ParseKeyHash(key_hash_string) + return &FileId{VolumeId: volumeId, Key: key, Hashcode: hash} +} +func (n *FileId) String() string { + bytes := make([]byte, 12) + util.Uint64toBytes(bytes[0:8], n.Key) + util.Uint32toBytes(bytes[8:12], n.Hashcode) + nonzero_index := 0 + for ; bytes[nonzero_index] == 0; nonzero_index++ { + } + return n.VolumeId.String() + "," + hex.EncodeToString(bytes[nonzero_index:]) +} diff --git a/go/storage/needle.go b/go/storage/needle.go index 755b3eafd..256a7c26a 100644 --- a/go/storage/needle.go +++ b/go/storage/needle.go @@ -36,7 +36,7 @@ type Needle struct { Padding []byte `comment:"Aligned to 8 bytes"` } -func NewNeedle(r *http.Request) (n *Needle, fname string, e error) { +func NewNeedle(r *http.Request) (n *Needle, e error) { n = new(Needle) form, fe := r.MultipartReader() @@ -51,7 +51,7 @@ func NewNeedle(r *http.Request) (n *Needle, fname string, e error) { e = fe return } - fname = part.FileName() + fname := part.FileName() if fname != "" { fname = path.Base(part.FileName()) } else { |
