Skip to content

Commit

Permalink
reloved merge conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
samvel-vardanyan committed Aug 16, 2023
1 parent 939ee03 commit 0b30365
Show file tree
Hide file tree
Showing 11 changed files with 349 additions and 228 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
packages = ./model/... ./core/... ./contract/... ./contentadrstorage/...

test:
tests:
go test ${packages}

lint:
Expand Down
33 changes: 18 additions & 15 deletions contract/pkg/bucket/messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ type (
Balance = types.U128
Cash = Balance
Resource = uint32
NodeId = uint32
Token = uint64
ClusterId = uint32
AccountId = types.AccountID
Expand All @@ -22,20 +21,18 @@ type (
BucketParams = Params
CdnNodeParams = Params
NodeState = byte
NodeKey = uint64
NodeKey = string
VNodes = [][]Token
)

const (
UNKNOWN NodeState = iota
ADDING
ADDING = iota
ACTIVE
DELETING
OFFLINE
)

var NodeTags = map[string]byte{
"UNKNOWN": UNKNOWN,
"ADDING": ADDING,
"ACTIVE": ACTIVE,
"DELETING": DELETING,
Expand All @@ -44,27 +41,33 @@ var NodeTags = map[string]byte{

type Cluster struct {
ManagerId AccountId
NodesKeys []string
Params Params
NodesKeys []NodeKey
ResourcePerVNode Resource
ResourceUsed Resource
Revenues Cash
Nodes []NodeKey
VNodes [][]Token
TotalRent Balance
CdnNodesKeys []string
CdnUsdPerGb Balance
CdnNodesKeys []NodeKey
CdnRevenues Cash
CdnUsdPerGb Balance
}

type NewCluster struct {
Params Params
ResourcePerVNode Resource
type NodeVNodesInfo struct {
NodeKey NodeKey
VNodes []Token
}

type ClusterStatus struct {
ClusterId ClusterId
Cluster Cluster
Params Params
ClusterId ClusterId
Cluster Cluster
NodesVNodes []NodeVNodesInfo
}

type NewCluster struct {
Params Params
ResourcePerVNode Resource
}

type CDNCluster struct {
Expand Down Expand Up @@ -322,7 +325,7 @@ type ClusterParams struct {

func (c *ClusterStatus) ReplicationFactor() uint {
params := &ClusterParams{}
err := json.Unmarshal([]byte(c.Params), params)
err := json.Unmarshal([]byte(c.Cluster.Params), params)
if err != nil || params.ReplicationFactor <= 0 {
return 0
}
Expand Down
30 changes: 17 additions & 13 deletions contract/pkg/bucket/messages_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ package bucket

import (
"encoding/hex"
"github.com/cerebellum-network/cere-ddc-sdk-go/contract/pkg"
"strings"
"testing"

"github.com/cerebellum-network/cere-ddc-sdk-go/contract/pkg"

"github.com/centrifuge/go-substrate-rpc-client/v4/types"
"github.com/stretchr/testify/assert"
)
Expand All @@ -28,9 +29,9 @@ func TestBucketWriteAccess(t *testing.T) {

func TestClusterStatus_ReplicationFactor(t *testing.T) {
type fields struct {
ClusterId ClusterId
Cluster Cluster
Params Params
ClusterId ClusterId
Cluster Cluster
NodesVNodes []NodeVNodesInfo
}
tests := []struct {
name string
Expand All @@ -41,36 +42,39 @@ func TestClusterStatus_ReplicationFactor(t *testing.T) {
name: "ReplicationFactor as integer",
fields: fields{
ClusterId: 1,
Params: `{"ReplicationFactor": 3}`,
Cluster: Cluster{},
Cluster: Cluster{
Params: `{"ReplicationFactor": 3}`,
},
},
want: 3,
},
{
name: "ReplicationFactor as string",
fields: fields{
ClusterId: 1,
Params: `{"ReplicationFactor": "3"}`,
Cluster: Cluster{},
Cluster: Cluster{
Params: `{"ReplicationFactor": "3"}`,
},
},
want: 3,
},
{
name: "ReplicationFactor not set",
fields: fields{
ClusterId: 1,
Params: `{}`,
Cluster: Cluster{},
Cluster: Cluster{
Params: `{}`,
},
},
want: 0,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
c := &ClusterStatus{
ClusterId: tt.fields.ClusterId,
Cluster: tt.fields.Cluster,
Params: tt.fields.Params,
ClusterId: tt.fields.ClusterId,
Cluster: tt.fields.Cluster,
NodesVNodes: tt.fields.NodesVNodes,
}
assert.Equalf(t, tt.want, c.ReplicationFactor(), "ReplicationFactor()")
})
Expand Down
6 changes: 3 additions & 3 deletions contract/pkg/cache/ddc_bucket_contract_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ type (
ClearNodes()
ClearBuckets()
ClearAccounts()
ClearNodeById(id bucket.NodeId)
ClearNodeById(id bucket.NodeKey)
ClearBucketById(id bucket.BucketId)
ClearAccountById(id bucket.AccountId)
bucket.DdcBucketContract
Expand Down Expand Up @@ -200,8 +200,8 @@ func (d *ddcBucketContractCached) ClearAccounts() {
d.accountCache.Flush()
}

func (d *ddcBucketContractCached) ClearNodeById(id bucket.NodeId) { //nolint:golint,unused
d.nodeCache.Delete(toString(id))
func (d *ddcBucketContractCached) ClearNodeById(key bucket.NodeKey) { //nolint:golint,unused
d.nodeCache.Delete(key)
}

func (d *ddcBucketContractCached) ClearNodeByKey(nodeKey string) {
Expand Down
31 changes: 23 additions & 8 deletions contract/pkg/mock/ddc_bucket_contract_mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,14 @@ type (
}

Cluster struct {
Id uint32
VNodes [][]uint64
Nodes []uint32
Params string
Id uint32
NodesVNodes []NodeVNodes
Params string
}

NodeVNodes struct {
NodeKey string
VNodes []uint64
}

CDNNode struct {
Expand All @@ -55,7 +59,7 @@ type (

CDNCluster struct {
Id uint32
Nodes []uint32
Nodes []string
}

ddcBucketContractMock struct {
Expand All @@ -69,6 +73,18 @@ type (
}
)

func mapNodesVNodes(nodes []NodeVNodes) []bucket.NodeVNodesInfo {
var nodesVNodes []bucket.NodeVNodesInfo
for _, node := range nodes {
nodeVNodes := bucket.NodeVNodesInfo{
NodeKey: node.NodeKey,
VNodes: node.VNodes,
}
nodesVNodes = append(nodesVNodes, nodeVNodes)
}
return nodesVNodes
}

func CreateDdcBucketContractMock(apiUrl string, accountId string, nodes []Node, clusters []Cluster, cdnNodes []CDNNode, cdnClusters []CDNCluster) bucket.DdcBucketContract {
log.Info("DDC Bucket contract configured [MOCK]")
return &ddcBucketContractMock{
Expand Down Expand Up @@ -102,14 +118,13 @@ func (d *ddcBucketContractMock) ClusterGet(clusterId uint32) (*bucket.ClusterSta
ClusterId: clusterId,
Cluster: bucket.Cluster{
ManagerId: types.AccountID{},
Nodes: cluster.Nodes,
VNodes: cluster.VNodes,
Params: cluster.Params,
ResourcePerVNode: 32,
ResourceUsed: 0,
Revenues: types.NewU128(*big.NewInt(1)),
TotalRent: types.NewU128(*big.NewInt(1)),
},
Params: cluster.Params,
NodesVNodes: mapNodesVNodes(cluster.NodesVNodes),
}, nil
}
}
Expand Down
19 changes: 10 additions & 9 deletions core/pkg/topology/sync/topology.go
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
package sync

import (
"github.com/cerebellum-network/cere-ddc-sdk-go/core/pkg/topology"
"sync"

"github.com/cerebellum-network/cere-ddc-sdk-go/core/pkg/topology"
)

type ring struct {
ring topology.Ring
mutex sync.RWMutex
}

func NewTopology(nodeIds []uint32, vNodes [][]uint64, replicaFactor uint) topology.Ring {
func NewTopology(nodes topology.NodesVNodes, replicaFactor uint) topology.Ring {
return &ring{
ring: topology.NewTopology(nodeIds, vNodes, replicaFactor),
ring: topology.NewTopology(nodes, replicaFactor),
}
}

func (r *ring) Tokens(nodeId uint32) []uint64 {
func (r *ring) Tokens(nodeKey string) []uint64 {
r.mutex.RLock()
result := r.ring.Tokens(nodeId)
result := r.ring.Tokens(nodeKey)
r.mutex.RUnlock()

return result
Expand All @@ -40,17 +41,17 @@ func (r *ring) Replicas(token uint64) []topology.VNode {
return result
}

func (r *ring) Partitions(nodeId uint32) []topology.Partition {
func (r *ring) Partitions(nodeKey string) []topology.Partition {
r.mutex.RLock()
result := r.ring.Partitions(nodeId)
result := r.ring.Partitions(nodeKey)
r.mutex.RUnlock()

return result
}

func (r *ring) ExcessPartitions(nodeId uint32) []topology.Partition {
func (r *ring) ExcessPartitions(nodeKey string) []topology.Partition {
r.mutex.RLock()
result := r.ring.ExcessPartitions(nodeId)
result := r.ring.ExcessPartitions(nodeKey)
r.mutex.RUnlock()

return result
Expand Down
Loading

0 comments on commit 0b30365

Please sign in to comment.