Browse Source
refactoring: add type for needle id, offset
refactoring: add type for needle id, offset
later the type size can possibly be adjustedpull/680/head
Chris Lu
7 years ago
26 changed files with 356 additions and 268 deletions
-
3weed/command/export.go
-
16weed/command/filer.go
-
5weed/command/fix.go
-
11weed/operation/sync_volume.go
-
9weed/server/volume_server_handlers_sync.go
-
35weed/storage/file_id.go
-
50weed/storage/needle.go
-
7weed/storage/needle/btree_map.go
-
27weed/storage/needle/compact_map.go
-
9weed/storage/needle/compact_map_perf_test.go
-
19weed/storage/needle/compact_map_test.go
-
13weed/storage/needle/needle_value.go
-
10weed/storage/needle/needle_value_map.go
-
31weed/storage/needle_map.go
-
44weed/storage/needle_map_boltdb.go
-
41weed/storage/needle_map_leveldb.go
-
34weed/storage/needle_map_memory.go
-
35weed/storage/needle_map_metric.go
-
71weed/storage/needle_read_write.go
-
4weed/storage/needle_test.go
-
5weed/storage/store.go
-
79weed/storage/types/needle_types.go
-
15weed/storage/volume_checking.go
-
13weed/storage/volume_read_write.go
-
15weed/storage/volume_sync.go
-
23weed/storage/volume_vacuum.go
@ -1,8 +1,12 @@ |
|||
package needle |
|||
|
|||
import ( |
|||
. "github.com/chrislusf/seaweedfs/weed/storage/types" |
|||
) |
|||
|
|||
type NeedleValueMap interface { |
|||
Set(key Key, offset, size uint32) (oldOffset, oldSize uint32) |
|||
Delete(key Key) uint32 |
|||
Get(key Key) (*NeedleValue, bool) |
|||
Set(key NeedleId, offset Offset, size uint32) (oldOffset Offset, oldSize uint32) |
|||
Delete(key NeedleId) uint32 |
|||
Get(key NeedleId) (*NeedleValue, bool) |
|||
Visit(visit func(NeedleValue) error) error |
|||
} |
@ -0,0 +1,79 @@ |
|||
package types |
|||
|
|||
import ( |
|||
"math" |
|||
"github.com/chrislusf/seaweedfs/weed/util" |
|||
"strconv" |
|||
"fmt" |
|||
) |
|||
|
|||
type NeedleId uint64 |
|||
type Offset uint32 |
|||
type Cookie uint32 |
|||
|
|||
const ( |
|||
NeedleIdSize = 8 |
|||
OffsetSize = 4 |
|||
SizeSize = 4 // uint32 size
|
|||
NeedleEntrySize = NeedleIdSize + OffsetSize + SizeSize |
|||
NeedlePaddingSize = 8 |
|||
MaxPossibleVolumeSize = 4 * 1024 * 1024 * 1024 * 8 |
|||
TombstoneFileSize = math.MaxUint32 |
|||
CookieSize = 4 |
|||
) |
|||
|
|||
func NeedleIdToBytes(bytes []byte, needleId NeedleId) { |
|||
util.Uint64toBytes(bytes, uint64(needleId)) |
|||
} |
|||
|
|||
// NeedleIdToUint64 used to send max needle id to master
|
|||
func NeedleIdToUint64(needleId NeedleId) uint64 { |
|||
return uint64(needleId) |
|||
} |
|||
|
|||
func Uint64ToNeedleId(needleId uint64) (NeedleId) { |
|||
return NeedleId(needleId) |
|||
} |
|||
|
|||
func BytesToNeedleId(bytes []byte) (NeedleId) { |
|||
return NeedleId(util.BytesToUint64(bytes)) |
|||
} |
|||
|
|||
func CookieToBytes(bytes []byte, cookie Cookie) { |
|||
util.Uint32toBytes(bytes, uint32(cookie)) |
|||
} |
|||
func Uint32ToCookie(cookie uint32) (Cookie) { |
|||
return Cookie(cookie) |
|||
} |
|||
|
|||
func BytesToCookie(bytes []byte) (Cookie) { |
|||
return Cookie(util.BytesToUint32(bytes[0:4])) |
|||
} |
|||
|
|||
func OffsetToBytes(bytes []byte, offset Offset) { |
|||
util.Uint32toBytes(bytes, uint32(offset)) |
|||
} |
|||
|
|||
func BytesToOffset(bytes []byte) (Offset) { |
|||
return Offset(util.BytesToUint32(bytes[0:4])) |
|||
} |
|||
|
|||
func (k NeedleId) String() string { |
|||
return strconv.FormatUint(uint64(k), 10) |
|||
} |
|||
|
|||
func ParseNeedleId(idString string) (NeedleId, error) { |
|||
key, err := strconv.ParseUint(idString, 16, 64) |
|||
if err != nil { |
|||
return 0, fmt.Errorf("needle id %s format error: %v", idString, err) |
|||
} |
|||
return NeedleId(key), nil |
|||
} |
|||
|
|||
func ParseCookie(cookieString string) (Cookie, error) { |
|||
cookie, err := strconv.ParseUint(cookieString, 16, 32) |
|||
if err != nil { |
|||
return 0, fmt.Errorf("needle cookie %s format error: %v", cookieString, err) |
|||
} |
|||
return Cookie(cookie), nil |
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue