-
Notifications
You must be signed in to change notification settings - Fork 40
/
object_integrity_schema.go
51 lines (42 loc) · 1.47 KB
/
object_integrity_schema.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package sqldb
import (
"fmt"
)
const (
IntegrityMetasNumberOfShards = 64
ReasonableTableSize = 5_000_000
ListObjectsDefaultSize = 1000
)
// PieceHashTable table schema
type PieceHashTable struct {
ObjectID uint64 `gorm:"primary_key"`
SegmentIndex uint32 `gorm:"primary_key"`
RedundancyIndex int32 `gorm:"primary_key"`
PieceChecksum string
Version int64
}
// TableName is used to set PieceHashTable schema's table name in database
func (PieceHashTable) TableName() string {
return PieceHashTableName
}
// IntegrityMetaTable table schema
type IntegrityMetaTable struct {
ObjectID uint64 `gorm:"primary_key"`
RedundancyIndex int32 `gorm:"primary_key"`
IntegrityChecksum string
PieceChecksumList string
}
// TableName is used to set IntegrityMetaTable schema's table name in database
func (IntegrityMetaTable) TableName() string {
return IntegrityMetaTableName
}
func GetIntegrityMetasTableName(objectID uint64) string {
return GetIntegrityMetasTableNameByShardNumber(int(GetIntegrityMetasShardNumberByBucketName(objectID)))
}
// GetIntegrityMetasShardNumberByBucketName Allocate each shard table with 5,000,000 continuous entry before using the next shard table
func GetIntegrityMetasShardNumberByBucketName(objectID uint64) uint64 {
return objectID / ReasonableTableSize % IntegrityMetasNumberOfShards
}
func GetIntegrityMetasTableNameByShardNumber(shard int) string {
return fmt.Sprintf("%s_%02d", IntegrityMetaTableName, shard)
}