Commit b254a74d authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent e0e31499
......@@ -106,17 +106,33 @@ type PeerNode struct {
dialing *dialed
}
// Len returns N(entries) in the table.
// RONodeTable provides read-only access to NodeTable.
type RONodeTable interface {
// Len returns N(entries) in the table.
Len() int
// All returns all entries in the table as one slice.
All() []*PeerNode
// Get finds node by node ID.
Get(nid proto.NodeID) *PeerNode
// XXX ? StorageList
// XXX ? String
}
// Len implements RONodeTable.
func (nt *NodeTable) Len() int {
return len(nt.nodev)
}
// All returns all entries in the table as one slice.
// All implements RONodeTable.
func (nt *NodeTable) All() []*PeerNode {
return nt.nodev
}
// Get finds node by node ID.
// Get implements RONodeTable.
func (nt *NodeTable) Get(nid proto.NodeID) *PeerNode {
// FIXME linear scan
for _, node := range nt.nodev {
......
......@@ -137,10 +137,31 @@ type Cell struct {
}
// R returns n(replica) for partition table.
// ROPartitionTable provides read-only access to PartitionTable.
type ROPartitionTable interface {
// R returns n(replica) for partition table.
R() int
// Get returns cells oid is associated with.
Get(oid zodb.Oid) []Cell
// OperationalWith checks whether all object space is covered by at least some ready-to-serve nodes.
//
// for all partitions it checks both:
// - whether there are up-to-date entries in the partition table, and
// - whether there are corresponding storage nodes that are up
//
// information about nodes being up or down is obtained from supplied NodeTable
OperationalWith(nt RONodeTable) bool
// XXX String ?
// XXX ToMsg ?
}
// R implements ROPartitionTable.
func (pt *PartitionTable) R() int { return pt.r_ + 1 }
// Get returns cells oid is associated with.
// Get implements ROPartitionTable.
func (pt *PartitionTable) Get(oid zodb.Oid) []Cell {
if len(pt.tab) == 0 {
return nil
......@@ -178,14 +199,8 @@ func MakePartTab(np int, nreplica int, nodev []*PeerNode) *PartitionTable {
}
// OperationalWith checks whether all object space is covered by at least some ready-to-serve nodes.
//
// for all partitions it checks both:
// - whether there are up-to-date entries in the partition table, and
// - whether there are corresponding storage nodes that are up
//
// information about nodes being up or down is obtained from supplied NodeTable
func (pt *PartitionTable) OperationalWith(nt *NodeTable) bool {
// OperationalWith implements ROPartitionTable.
func (pt *PartitionTable) OperationalWith(nt RONodeTable) bool {
// empty partition table is never operational
if len(pt.tab) == 0 {
return false
......
// Copyright (C) 2016-2021 Nexedi SA and Contributors.
// Kirill Smelkov <kirr@nexedi.com>
//
// This program is free software: you can Use, Study, Modify and Redistribute
// it under the terms of the GNU General Public License version 3, or (at your
// option) any later version, as published by the Free Software Foundation.
//
// You can also Link and Combine this program with other software covered by
// the terms of any of the Free Software licenses or any of the Open Source
// Initiative approved licenses and Convey the resulting work. Corresponding
// source of such a combination shall include the source code for all other
// software used.
//
// This program is distributed WITHOUT ANY WARRANTY; without even the implied
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
//
// See COPYING file for full licensing terms.
// See https://www.nexedi.com/licensing for rationale and options.
package xneo
// transactional log of states
// XXX ...
type State struct {
NodeTab *NodeTable // nodes in the cluster
PartTab *PartitionTable // on which nodes which data is located
ClusterState proto.ClusterState // code for cluster state
}
type StateSnapshot interface {
NodeTab() RONodeTable
PartTab() ROPartitionTable
ClusterState() proto.ClusterState
}
// XXX transactional journal ...
type StateLog struct {
mu sync.Mutex
head *State
}
// ReadHead returns state from head of the log.
func (l *StateLog) ReadHead() StateSnapshot {
l.mu.Lock()
defer l.mu.Unlock()
return l.head
}
// CommitUpdate creates new entry in the log with state updated by δf's changes.
func (l *StateLog) CommitUpdate(δf func(*State)) {
l.mu.Lock()
defer l.mu.Unlock()
s := l.head.Clone()
δf(s)
l.head = s
}
......@@ -151,10 +151,11 @@ func NewNode(typ proto.NodeType, clusterName string, net xnet.Networker, masterA
}
// XXX -> use statelog instead
/*
// XXX doc, naming
// XXX WithStateHead ? WithStateSnapshot ? -> ReadState ?
func (node *Node) WithState(f func(*/*readonly*/State)) {
func (node *Node) WithState(f func(*readonlyState)) {
node.stateLogMu.Lock()
s := node.state
node.stateLogMu.Unlock()
......@@ -169,3 +170,4 @@ func (node *Node) ModifyState(δf func(*State)) {
δf(s)
node.state = s
}
*/
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment