apistore: Lock accesses
This commit is contained in:
parent
2c89b3240f
commit
8c1bc10aa4
@ -50,9 +50,14 @@ type APIBlockstoreAccessor struct {
|
|||||||
|
|
||||||
retrStores map[retrievalmarket.DealID]api.RemoteStoreID
|
retrStores map[retrievalmarket.DealID]api.RemoteStoreID
|
||||||
remoteStores map[api.RemoteStoreID]bstore.Blockstore
|
remoteStores map[api.RemoteStoreID]bstore.Blockstore
|
||||||
|
|
||||||
|
accessLk sync.Locker
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *APIBlockstoreAccessor) Get(id retrievalmarket.DealID, payloadCID retrievalmarket.PayloadCID) (bstore.Blockstore, error) {
|
func (a *APIBlockstoreAccessor) Get(id retrievalmarket.DealID, payloadCID retrievalmarket.PayloadCID) (bstore.Blockstore, error) {
|
||||||
|
a.accessLk.Lock()
|
||||||
|
defer a.accessLk.Unlock()
|
||||||
|
|
||||||
as, has := a.retrStores[id]
|
as, has := a.retrStores[id]
|
||||||
if !has {
|
if !has {
|
||||||
return a.sub.Get(id, payloadCID)
|
return a.sub.Get(id, payloadCID)
|
||||||
@ -62,6 +67,9 @@ func (a *APIBlockstoreAccessor) Get(id retrievalmarket.DealID, payloadCID retrie
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (a *APIBlockstoreAccessor) Done(id retrievalmarket.DealID) error {
|
func (a *APIBlockstoreAccessor) Done(id retrievalmarket.DealID) error {
|
||||||
|
a.accessLk.Lock()
|
||||||
|
defer a.accessLk.Unlock()
|
||||||
|
|
||||||
if _, has := a.retrStores[id]; has {
|
if _, has := a.retrStores[id]; has {
|
||||||
delete(a.retrStores, id)
|
delete(a.retrStores, id)
|
||||||
return nil
|
return nil
|
||||||
@ -70,6 +78,9 @@ func (a *APIBlockstoreAccessor) Done(id retrievalmarket.DealID) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (a *APIBlockstoreAccessor) UseRetrievalStore(id retrievalmarket.DealID, sid api.RemoteStoreID) error {
|
func (a *APIBlockstoreAccessor) UseRetrievalStore(id retrievalmarket.DealID, sid api.RemoteStoreID) error {
|
||||||
|
a.accessLk.Lock()
|
||||||
|
defer a.accessLk.Unlock()
|
||||||
|
|
||||||
if _, has := a.retrStores[id]; has {
|
if _, has := a.retrStores[id]; has {
|
||||||
return xerrors.Errorf("apistore for deal %d already registered", id)
|
return xerrors.Errorf("apistore for deal %d already registered", id)
|
||||||
}
|
}
|
||||||
@ -82,6 +93,9 @@ func (a *APIBlockstoreAccessor) UseRetrievalStore(id retrievalmarket.DealID, sid
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (a *APIBlockstoreAccessor) RegisterApiStore(sid api.RemoteStoreID, st *lbstore.NetworkStore) error {
|
func (a *APIBlockstoreAccessor) RegisterApiStore(sid api.RemoteStoreID, st *lbstore.NetworkStore) error {
|
||||||
|
a.accessLk.Lock()
|
||||||
|
defer a.accessLk.Unlock()
|
||||||
|
|
||||||
if _, has := a.remoteStores[sid]; has {
|
if _, has := a.remoteStores[sid]; has {
|
||||||
return xerrors.Errorf("remote store already registered with this uuid")
|
return xerrors.Errorf("remote store already registered with this uuid")
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user