Skip to content

Commit 53b4111

Browse files
committed
feat: support static available storage
1 parent 4df761d commit 53b4111

4 files changed

Lines changed: 20 additions & 6 deletions

File tree

node/rpc/node_rpc_server.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -222,10 +222,9 @@ func (r *RPCServer) GetWorkerInfo(
222222
info := []*protobufs.WorkerInfo{}
223223
for _, worker := range workers {
224224
info = append(info, &protobufs.WorkerInfo{
225-
CoreId: uint32(worker.CoreId),
226-
Filter: worker.Filter,
227-
// TODO(2.1.1+): Expose available storage
228-
AvailableStorage: uint64(worker.TotalStorage),
225+
CoreId: uint32(worker.CoreId),
226+
Filter: worker.Filter,
227+
AvailableStorage: uint64(worker.AvailableStorage),
229228
TotalStorage: uint64(worker.TotalStorage),
230229
})
231230
}

node/store/worker.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,9 +190,9 @@ func encodeWorkerInfo(worker *store.WorkerInfo) ([]byte, error) {
190190
streamListenMultiaddrLen := uint16(len(worker.StreamListenMultiaddr))
191191
filterLen := uint16(len(worker.Filter))
192192

193-
// totalLen = coreId(8) + totalStorage(8) + automatic(1) + allocated(1)
193+
// totalLen = coreId(8) + totalStorage(8) + availableStorage(8) + automatic(1) + allocated(1)
194194
// + 2 + listen + 2 + stream + 2 + filter
195-
totalLen := 8 + 8 + 1 + 1 + 2 + int(listenMultiaddrLen) + 2 +
195+
totalLen := 8 + 8 + 8 + 1 + 1 + 2 + int(listenMultiaddrLen) + 2 +
196196
int(streamListenMultiaddrLen) + 2 + int(filterLen)
197197
data := make([]byte, totalLen)
198198

@@ -203,6 +203,9 @@ func encodeWorkerInfo(worker *store.WorkerInfo) ([]byte, error) {
203203
binary.BigEndian.PutUint64(data[offset:], uint64(worker.TotalStorage))
204204
offset += 8
205205

206+
binary.BigEndian.PutUint64(data[offset:], uint64(worker.AvailableStorage))
207+
offset += 8
208+
206209
if worker.Automatic {
207210
data[offset] = 1
208211
} else {
@@ -252,6 +255,15 @@ func decodeWorkerInfo(data []byte) (*store.WorkerInfo, error) {
252255
totalStorage := binary.BigEndian.Uint64(data[offset:])
253256
offset += 8
254257

258+
var availableStorage uint64
259+
// Backwards compatibility
260+
if offset+8 <= len(data) {
261+
availableStorage = binary.BigEndian.Uint64(data[offset:])
262+
offset += 8
263+
} else {
264+
availableStorage = totalStorage
265+
}
266+
255267
if offset+1 > len(data) {
256268
return nil, errors.New("truncated automatic flag")
257269
}
@@ -312,6 +324,7 @@ func decodeWorkerInfo(data []byte) (*store.WorkerInfo, error) {
312324
StreamListenMultiaddr: streamListenMultiaddr,
313325
Filter: filter,
314326
TotalStorage: uint(totalStorage),
327+
AvailableStorage: uint(availableStorage),
315328
Automatic: automatic,
316329
Allocated: allocated,
317330
}, nil

node/worker/manager.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -636,6 +636,7 @@ func (w *WorkerManager) getIPCOfWorker(coreId uint) (
636636
StreamListenMultiaddr: addr.String(),
637637
Filter: nil,
638638
TotalStorage: 0,
639+
AvailableStorage: 0,
639640
Automatic: len(w.config.Engine.DataWorkerP2PMultiaddrs) == 0,
640641
Allocated: false,
641642
})

types/store/worker.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ type WorkerInfo struct {
66
StreamListenMultiaddr string
77
Filter []byte
88
TotalStorage uint
9+
AvailableStorage uint
910
Automatic bool
1011
Allocated bool
1112
}

0 commit comments

Comments
 (0)