diff --git a/go.mod b/go.mod index 67978cd12..73a6f50d6 100644 --- a/go.mod +++ b/go.mod @@ -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 @@ -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 diff --git a/go.sum b/go.sum index 98fb37797..46c370f42 100644 --- a/go.sum +++ b/go.sum @@ -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= @@ -35,6 +36,8 @@ 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= @@ -42,15 +45,16 @@ github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/ 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= @@ -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= @@ -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= @@ -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= @@ -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= @@ -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= diff --git a/pkg/stone/upload_payload_stone_test.go b/pkg/stone/upload_payload_stone_test.go index bf7c4426d..cbac3d9c6 100644 --- a/pkg/stone/upload_payload_stone_test.go +++ b/pkg/stone/upload_payload_stone_test.go @@ -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 ( @@ -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 } diff --git a/proto/.gitkeep b/proto/.gitkeep deleted file mode 100644 index e69de29bb..000000000 diff --git a/service/stonehub/stone_hub.go b/service/stonehub/stone_hub.go index cd2e3b59f..f4d16e2aa 100644 --- a/service/stonehub/stone_hub.go +++ b/service/stonehub/stone_hub.go @@ -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" @@ -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)) } diff --git a/service/stonehub/stone_hub_config.go b/service/stonehub/stone_hub_config.go index 1efb32145..ffc9c7048 100644 --- a/service/stonehub/stone_hub_config.go +++ b/service/stonehub/stone_hub_config.go @@ -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 ( @@ -19,6 +20,7 @@ type StoneHubConfig struct { JobDBType string JobDB *jobsql.DBOption MetaDBType string + MetaDB *leveldb.MetaLevelDBConfig } var DefaultStorageProvider = "bnb-sp" @@ -40,4 +42,5 @@ var DefaultStoneHubConfig = &StoneHubConfig{ Database: "job_context", }, MetaDBType: LevelDB, + MetaDB: leveldb.DefaultMetaLevelDBConfig, } diff --git a/store/metadb/leveldb/meta_config.go b/store/metadb/leveldb/meta_config.go new file mode 100644 index 000000000..6ca60a675 --- /dev/null +++ b/store/metadb/leveldb/meta_config.go @@ -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, +} diff --git a/store/metadb/leveldb/meta_db.go b/store/metadb/leveldb/meta_db.go new file mode 100644 index 000000000..505a33690 --- /dev/null +++ b/store/metadb/leveldb/meta_db.go @@ -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 +} diff --git a/store/metadb/leveldb/meta_schema.go b/store/metadb/leveldb/meta_schema.go new file mode 100644 index 000000000..74b83888d --- /dev/null +++ b/store/metadb/leveldb/meta_schema.go @@ -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...) +} diff --git a/store/metadb/meta_db.go b/store/metadb/meta_db.go index 619a77418..2c9680eed 100644 --- a/store/metadb/meta_db.go +++ b/store/metadb/meta_db.go @@ -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) } diff --git a/store/metadb/meta_db_test.go b/store/metadb/meta_db_test.go new file mode 100644 index 000000000..e71d10e58 --- /dev/null +++ b/store/metadb/meta_db_test.go @@ -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) +}