aboutsummaryrefslogtreecommitdiff
path: root/go/storage
diff options
context:
space:
mode:
authorChris Lu <chris.lu@gmail.com>2014-08-31 23:25:54 -0700
committerChris Lu <chris.lu@gmail.com>2014-08-31 23:25:54 -0700
commit69343c5951a7e6a6e272393c1946c12d635b51b8 (patch)
tree634dfe70c1a02def0d314559eee987a38efddc52 /go/storage
parent57a4549d8678bb08f4ecbdede1939830471e3091 (diff)
downloadseaweedfs-69343c5951a7e6a6e272393c1946c12d635b51b8.tar.xz
seaweedfs-69343c5951a7e6a6e272393c1946c12d635b51b8.zip
adding ttl field to volume super block
Diffstat (limited to 'go/storage')
-rw-r--r--go/storage/volume_super_block.go10
-rw-r--r--go/storage/volume_super_block_test.go22
2 files changed, 32 insertions, 0 deletions
diff --git a/go/storage/volume_super_block.go b/go/storage/volume_super_block.go
index 95f7c30bb..35030b93e 100644
--- a/go/storage/volume_super_block.go
+++ b/go/storage/volume_super_block.go
@@ -2,6 +2,7 @@ package storage
import (
"code.google.com/p/weed-fs/go/glog"
+ "code.google.com/p/weed-fs/go/util"
"fmt"
"os"
)
@@ -10,9 +11,16 @@ const (
SuperBlockSize = 8
)
+/*
+* Super block currently has 8 bytes allocated for each volume.
+* Byte 0: version, 1 or 2
+* Byte 1: Replica Placement strategy, 000, 001, 002, 010, etc
+* Byte 2 and byte 3: Time to live in minutes
+ */
type SuperBlock struct {
version Version
ReplicaPlacement *ReplicaPlacement
+ Ttl uint16
}
func (s *SuperBlock) Version() Version {
@@ -22,6 +30,7 @@ func (s *SuperBlock) Bytes() []byte {
header := make([]byte, SuperBlockSize)
header[0] = byte(s.version)
header[1] = s.ReplicaPlacement.Byte()
+ util.Uint16toBytes(header[2:4], s.Ttl)
return header
}
@@ -61,5 +70,6 @@ func ParseSuperBlock(header []byte) (superBlock SuperBlock, err error) {
if superBlock.ReplicaPlacement, err = NewReplicaPlacementFromByte(header[1]); err != nil {
err = fmt.Errorf("cannot read replica type: %s", err.Error())
}
+ superBlock.Ttl = util.BytesToUint16(header[2:4])
return
}
diff --git a/go/storage/volume_super_block_test.go b/go/storage/volume_super_block_test.go
new file mode 100644
index 000000000..19a1bb757
--- /dev/null
+++ b/go/storage/volume_super_block_test.go
@@ -0,0 +1,22 @@
+package storage
+
+import (
+ "testing"
+)
+
+func TestSuperBlockReadWrite(t *testing.T) {
+ rp, _ := NewReplicaPlacementFromByte(byte(001))
+ s := &SuperBlock{
+ version: CurrentVersion,
+ ReplicaPlacement: rp,
+ Ttl: uint16(35),
+ }
+
+ bytes := s.Bytes()
+
+ if !(bytes[2] == 0 && bytes[3] == 35) {
+ println("byte[2]:", bytes[2], "byte[3]:", bytes[3])
+ t.Fail()
+ }
+
+}