Skip to content

Commit

Permalink
code cleanup
Browse files Browse the repository at this point in the history
there was only one lock mode in use, so no need for all the extra code.
  • Loading branch information
sni committed Nov 25, 2024
1 parent 9f6b19e commit 6aeee04
Show file tree
Hide file tree
Showing 5 changed files with 4 additions and 46 deletions.
16 changes: 1 addition & 15 deletions pkg/lmd/datarow.go
Original file line number Diff line number Diff line change
Expand Up @@ -439,21 +439,7 @@ func (d *DataRow) getVirtualRowValue(col *Column) interface{} {
value, ok = d.getVirtualSubLMDValue(col)
}
if !ok {
switch d.DataStore.PeerLockMode {
case PeerLockModeFull:
value = peer.statusGet(col.VirtualMap.StatusKey)
case PeerLockModeSimple:
switch col.VirtualMap.StatusKey {
case PeerName:
return &(peer.Name)
case PeerKey:
return &(peer.ID)
case ProgramStart:
return &(peer.ProgramStart)
default:
value = peer.statusGetLocked(col.VirtualMap.StatusKey)
}
}
value = peer.statusGet(col.VirtualMap.StatusKey)
}
} else {
value = col.VirtualMap.ResolveFunc(d, col)
Expand Down
2 changes: 0 additions & 2 deletions pkg/lmd/datastore.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ type DataStore struct {
Data []*DataRow // the actual data rows
Columns ColumnList // reference to the used columns
DynamicColumnNamesCache []string // contains list of keys used to run periodic update
PeerLockMode PeerLockMode // flag wether datarow have to set PeerLock when accessing status
}

// NewDataStore creates a new datastore with columns based on given flags.
Expand All @@ -37,7 +36,6 @@ func NewDataStore(table *Table, peer *Peer) (d *DataStore) {
DynamicColumnNamesCache: make([]string, 0),
dupStringList: make(map[[32]byte][]string),
Table: table,
PeerLockMode: table.PeerLockMode,
LowerCaseColumns: make(map[int]int),
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/lmd/objects.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func (o *ObjectsType) AddTable(name TableName, table *Table) {

// NewBackendsTable returns a new backends table.
func NewBackendsTable() (t *Table) {
t = &Table{Virtual: GetTableBackendsStore, WorksUnlocked: true, PeerLockMode: PeerLockModeFull}
t = &Table{Virtual: GetTableBackendsStore, WorksUnlocked: true}
t.AddPeerInfoColumn("peer_key", StringCol, "Id of this peer")
t.AddPeerInfoColumn("peer_name", StringCol, "Name of this peer")
t.AddPeerInfoColumn("key", StringCol, "Id of this peer")
Expand Down
18 changes: 2 additions & 16 deletions pkg/lmd/response.go
Original file line number Diff line number Diff line change
Expand Up @@ -573,21 +573,7 @@ func (res *Response) WriteDataResponse(json *jsoniter.Stream) {
// unprocessed result?
res.ResultTotal = res.RawResults.Total
res.RowsScanned = res.RawResults.RowsScanned

// PeerLockModeFull means we have to lock all peers before creating the result
if len(res.RawResults.DataResult) > 0 && res.RawResults.DataResult[0].DataStore.PeerLockMode == PeerLockModeFull {
res.WriteDataResponseRowLocked(json)

return
}

for i := range res.RawResults.DataResult {
if i > 0 {
json.WriteRaw(",\n")
json.Flush()
}
res.RawResults.DataResult[i].WriteJSON(json, res.Request.RequestColumns)
}
res.WriteDataResponseRowLocked(json)
default:
logWith(res).Errorf("response contains no result at all")
}
Expand Down Expand Up @@ -873,7 +859,7 @@ func (res *Response) buildLocalResponseData(ctx context.Context, store *DataStor

// for some tables its faster to lock the table only once
ds := store.DataSet
if store.PeerLockMode == PeerLockModeFull && ds != nil && ds.peer != nil {
if ds != nil && ds.peer != nil {
ds.peer.lock.RLock()
defer ds.peer.lock.RUnlock()
}
Expand Down
12 changes: 0 additions & 12 deletions pkg/lmd/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,6 @@ const (
TableServicesbyhostgroup
)

// PeerLockMode sets full or simple lock mode.
type PeerLockMode int

const (
// PeerLockModeSimple locks each peer.Status access separately.
PeerLockModeSimple PeerLockMode = iota

// PeerLockModeFull locks peer once before createing the result.
PeerLockModeFull
)

// NewTableName returns a table for given name or an error.
func NewTableName(name string) (TableName, error) {
switch strings.ToLower(name) {
Expand Down Expand Up @@ -157,7 +146,6 @@ type Table struct {
RefTables []TableRef // referenced tables
DefaultSort []string // columns used to sort if nothing is specified
Columns ColumnList
PeerLockMode PeerLockMode // should the peer be locked once for the complete result or on each access
Name TableName
WorksUnlocked bool // flag wether locking the peer.DataLock can be skipped to answer the query
PassthroughOnly bool // flag wether table will be cached or simply passed through to remote sites
Expand Down

0 comments on commit 6aeee04

Please sign in to comment.