Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: implement meta db #37

Merged
merged 1 commit into from
Jan 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ require (
github.com/oleiade/lane v1.0.1
github.com/pkg/sftp v1.13.5
github.com/stretchr/testify v1.8.1
github.com/syndtr/goleveldb v1.0.0
github.com/urfave/cli v1.22.10
github.com/viki-org/dnscache v0.0.0-20130720023526-c70c1f23c5d8
go.uber.org/multierr v1.9.0
Expand All @@ -32,6 +33,7 @@ require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/go-sql-driver/mysql v1.6.0 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db // indirect
github.com/jinzhu/inflection v1.0.0 // indirect
github.com/jinzhu/now v1.1.5 // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
Expand Down
22 changes: 18 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
github.com/go-sql-driver/mysql v1.6.0 h1:BCTh4TKNUYmOmMUcQ3IipzF5prigylS7XXjEkfCHuOE=
github.com/go-sql-driver/mysql v1.6.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
Expand All @@ -35,22 +36,25 @@ github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QD
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw=
github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db h1:woRePGFeVFfLKN/pOkfl+p/TAqKOfFu+7KPlMVpok/w=
github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/gorilla/mux v1.8.0 h1:i40aqfkR1h2SlN9hojwV5ZA91wcXFOvkdNIeFDP5koI=
github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So=
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E=
github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc=
github.com/jinzhu/now v1.1.4/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ=
github.com/jinzhu/now v1.1.5/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/gorilla/mux v1.8.0 h1:i40aqfkR1h2SlN9hojwV5ZA91wcXFOvkdNIeFDP5koI=
github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So=
github.com/jmespath/go-jmespath v0.4.0 h1:BEgLn5cpjn8UN1mAw4NjwDrS35OdebyEtFe+9YPoQUg=
github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo=
github.com/jmespath/go-jmespath/internal/testify v1.5.1 h1:shLQSRRSCCPj3f2gpwzGwWFoC7ycTf1rcQZHOlsJ6N8=
Expand All @@ -77,6 +81,9 @@ github.com/naoina/toml v0.1.1 h1:PT/lllxVVN0gzzSqSlHEmP8MJB4MY2U7STGxiouV4X8=
github.com/naoina/toml v0.1.1/go.mod h1:NBIhNtsFMo3G2szEBne+bO4gS192HuIYRqfvOWb4i1E=
github.com/oleiade/lane v1.0.1 h1:hXofkn7GEOubzTwNpeL9MaNy8WxolCYb9cInAIeqShU=
github.com/oleiade/lane v1.0.1/go.mod h1:IyTkraa4maLfjq/GmHR+Dxb4kCMtEGeb+qmhlrQ5Mk4=
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/sftp v1.13.5 h1:a3RLUqkyjYRtBTZJZ1VRrKbN3zhuPLlUc3sphVz81go=
Expand All @@ -97,6 +104,8 @@ github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/syndtr/goleveldb v1.0.0 h1:fBdIW9lB4Iz0n9khmH8w27SJ3QEJ7+IgjPEwGSZiFdE=
github.com/syndtr/goleveldb v1.0.0/go.mod h1:ZVVdQEZoIme9iO1Ch2Jdy24qqXrMMOU6lpPAyBWyWuQ=
github.com/urfave/cli v1.22.10 h1:p8Fspmz3iTctJstry1PYS3HVdllxnEzTEsgIgtxTrCk=
github.com/urfave/cli v1.22.10/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0=
github.com/viki-org/dnscache v0.0.0-20130720023526-c70c1f23c5d8 h1:EVObHAr8DqpoJCVv6KYTle8FEImKhtkfcZetNqxDoJQ=
Expand All @@ -123,6 +132,7 @@ golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
Expand All @@ -140,6 +150,7 @@ golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJ
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
Expand Down Expand Up @@ -200,6 +211,9 @@ google.golang.org/protobuf v1.28.1 h1:d0NfwRgPtno5B1Wa6L2DAG+KivqkdutMf1UhdNx175
google.golang.org/protobuf v1.28.1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10=
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
Expand Down
4 changes: 2 additions & 2 deletions pkg/stone/upload_payload_stone_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

types "github.com/bnb-chain/inscription-storage-provider/pkg/types/v1"
service "github.com/bnb-chain/inscription-storage-provider/service/types/v1"
"github.com/bnb-chain/inscription-storage-provider/store/jobdb"
"github.com/bnb-chain/inscription-storage-provider/store/jobdb/jobmemory"
)

var (
Expand All @@ -35,7 +35,7 @@ func InitENV() (*UploadPayloadStone, error) {
SpId: "bnb-test-sp",
},
}
jobDB := jobdb.NewMemJobDB()
jobDB := jobmemory.NewMemJobDB()
if err := jobDB.CreateUploadPayloadJob(txHash, object); err != nil {
return nil, err
}
Expand Down
Empty file removed proto/.gitkeep
Empty file.
10 changes: 9 additions & 1 deletion service/stonehub/stone_hub.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import (
"google.golang.org/grpc"
"google.golang.org/grpc/reflection"

"github.com/bnb-chain/inscription-storage-provider/store/metadb/leveldb"

"github.com/bnb-chain/inscription-storage-provider/store/jobdb/jobsql"

"github.com/bnb-chain/inscription-storage-provider/mock"
Expand Down Expand Up @@ -107,7 +109,13 @@ func (hub *StoneHub) initDB() (err error) {
switch hub.config.MetaDBType {
case LevelDB:
// TODO:: add leveldb, temporarily replace with memory job db
hub.metaDB = jobmemory.NewMemJobDB()
if hub.config.MetaDB == nil {
hub.config.MetaDB = DefaultStoneHubConfig.MetaDB
}
hub.metaDB, err = leveldb.NewMetaDB(hub.config.MetaDB)
if err != nil {
return
}
default:
return errors.New(fmt.Sprintf("job db not support type %s", hub.config.MetaDBType))
}
Expand Down
3 changes: 3 additions & 0 deletions service/stonehub/stone_hub_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"encoding/hex"

"github.com/bnb-chain/inscription-storage-provider/store/jobdb/jobsql"
"github.com/bnb-chain/inscription-storage-provider/store/metadb/leveldb"
)

var (
Expand All @@ -19,6 +20,7 @@ type StoneHubConfig struct {
JobDBType string
JobDB *jobsql.DBOption
MetaDBType string
MetaDB *leveldb.MetaLevelDBConfig
}

var DefaultStorageProvider = "bnb-sp"
Expand All @@ -40,4 +42,5 @@ var DefaultStoneHubConfig = &StoneHubConfig{
Database: "job_context",
},
MetaDBType: LevelDB,
MetaDB: leveldb.DefaultMetaLevelDBConfig,
}
17 changes: 17 additions & 0 deletions store/metadb/leveldb/meta_config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package leveldb

type MetaLevelDBConfig struct {
Path string
NameSpace string
Cache int
FileHandles int
ReadOnly bool
}

var DefaultMetaLevelDBConfig = &MetaLevelDBConfig{
Path: "./data",
NameSpace: "bnb-sp",
Cache: 4096,
FileHandles: 100000,
ReadOnly: false,
}
105 changes: 105 additions & 0 deletions store/metadb/leveldb/meta_db.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
package leveldb

import (
"encoding/json"

"github.com/syndtr/goleveldb/leveldb"
"github.com/syndtr/goleveldb/leveldb/errors"
"github.com/syndtr/goleveldb/leveldb/filter"
"github.com/syndtr/goleveldb/leveldb/opt"

"github.com/bnb-chain/inscription-storage-provider/store/metadb"
)

const (
// minCache is the minimum amount of memory in megabytes to allocate to leveldb
// read and write caching, split half and half.
minCache = 16

// minHandles is the minimum number of files handles to allocate to the open
// database files.
minHandles = 16
)

// Database is a persistent key-value store.
type Database struct {
Path string
Namespace string
db *leveldb.DB // LevelDB instance
}

// NewMetaDB call NewCustomMetaDB return Database instance.
func NewMetaDB(config *MetaLevelDBConfig) (*Database, error) {
return NewCustomMetaDB(config.Path, config.NameSpace, config.Cache, config.FileHandles, config.ReadOnly)
}

// NewCustomMetaDB return Database instance.
func NewCustomMetaDB(path string, namespace string, cache int, handles int, readonly bool) (*Database, error) {
// init options
optionFunc := func() *opt.Options {
options := &opt.Options{
Filter: filter.NewBloomFilter(10),
}
// Ensure we have some minimal caching and file guarantees
if cache < minCache {
cache = minCache
}
if handles < minHandles {
handles = minHandles
}
// Set default options
options.OpenFilesCacheCapacity = handles
options.BlockCacheCapacity = cache / 2 * opt.MiB
options.WriteBuffer = cache / 4 * opt.MiB // Two of these are used internally
if readonly {
options.ReadOnly = true
}
return options
}
options := optionFunc()

// Open the db and recover any potential corruptions
db, err := leveldb.OpenFile(path, options)
if _, corrupted := err.(*errors.ErrCorrupted); corrupted {
db, err = leveldb.RecoverFile(path, nil)
}
if err != nil {
return nil, err
}

// Assemble the wrapper with all the registered metrics
ldb := &Database{
Path: path,
Namespace: namespace,
db: db,
}
return ldb, nil
}

// Close the leveldb resource.
func (db *Database) Close() error {
return db.db.Close()
}

// SetIntegrityMeta put integrity hash info to db.
func (db *Database) SetIntegrityMeta(meta *metadb.IntegrityMeta) error {
if meta == nil {
return errors.New("primary integrity meta is nil")
}
data, err := json.Marshal(meta)
if err != nil {
return err
}
return db.db.Put(IntegrityMetaKey(db.Namespace, meta.ObjectID), data, nil)
}

// GetIntegrityMeta return the integrity hash info
func (db *Database) GetIntegrityMeta(objectID uint64) (*metadb.IntegrityMeta, error) {
data, err := db.db.Get(IntegrityMetaKey(db.Namespace, objectID), nil)
if err != nil {
return nil, err
}
var meta metadb.IntegrityMeta
err = json.Unmarshal(data, &meta)
return &meta, err
}
16 changes: 16 additions & 0 deletions store/metadb/leveldb/meta_schema.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package leveldb

import "encoding/binary"

// The fields below define the low level database schema prefixing.
var (
// IntegrityMetaPrefix + objectID -> PrimaryIntegrityMetaKey
IntegrityMetaPrefix = []byte("IntegrityMeta")
)

// IntegrityMetaKey return the integrity meta key.
func IntegrityMetaKey(prefix string, objectID uint64) []byte {
var buf = make([]byte, 8)
binary.BigEndian.PutUint64(buf, objectID)
return append(append([]byte(prefix), IntegrityMetaPrefix...), buf...)
}
18 changes: 18 additions & 0 deletions store/metadb/meta_db.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,22 @@
package metadb

import types "github.com/bnb-chain/inscription-storage-provider/pkg/types/v1"

// IntegrityMeta defines the integrity hash info
type IntegrityMeta struct {
ObjectID uint64 `json:"ObjectID"`
PieceIdx uint32 `json:"PieceIdx"`
PieceCount uint32 `json:"PieceCount"`
IsPrimary bool `json:"IsPrimary"`
RedundancyType types.RedundancyType `json:"RedundancyType"`

IntegrityHash []byte `json:"IntegrityHash"`
PieceHash map[string][]byte `json:"PieceHash"`
}

type MetaDB interface {
// SetIntegrityMeta put integrity hash info to db.
SetIntegrityMeta(meta *IntegrityMeta) error
// GetIntegrityMeta return the integrity hash info
GetIntegrityMeta(objectID uint64) (*IntegrityMeta, error)
}
28 changes: 28 additions & 0 deletions store/metadb/meta_db_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package metadb

import (
"encoding/json"
"fmt"
"testing"

"github.com/stretchr/testify/assert"

types "github.com/bnb-chain/inscription-storage-provider/pkg/types/v1"
)

func Test_IntegrityMeta_Json_Marshal_Unmarshal(t *testing.T) {
meta := &IntegrityMeta{
ObjectID: 1,
PieceIdx: 1,
RedundancyType: types.RedundancyType_REDUNDANCY_TYPE_REPLICA_TYPE,
}
data, err := json.Marshal(meta)
assert.Equal(t, nil, err)
fmt.Println(string(data))

var meta1 IntegrityMeta
err = json.Unmarshal(data, &meta1)
assert.Equal(t, nil, err)
assert.Equal(t, meta.ObjectID, meta1.ObjectID)
assert.Equal(t, meta.RedundancyType, meta1.RedundancyType)
}