better semantics for mpool clear local argument
local messages should be kept unless the parameter is true
This commit is contained in:
parent
3debf005a8
commit
817358f1bb
@ -184,7 +184,7 @@ type FullNode interface {
|
|||||||
MpoolGetNonce(context.Context, address.Address) (uint64, error)
|
MpoolGetNonce(context.Context, address.Address) (uint64, error)
|
||||||
MpoolSub(context.Context) (<-chan MpoolUpdate, error)
|
MpoolSub(context.Context) (<-chan MpoolUpdate, error)
|
||||||
|
|
||||||
// MpoolClear clears all pending messages from the mpool
|
// MpoolClear clears pending messages from the mpool
|
||||||
MpoolClear(context.Context, bool) error
|
MpoolClear(context.Context, bool) error
|
||||||
|
|
||||||
// MpoolGetConfig returns (a copy of) the current mpool config
|
// MpoolGetConfig returns (a copy of) the current mpool config
|
||||||
|
@ -496,8 +496,8 @@ func (c *FullNodeStruct) MpoolPending(ctx context.Context, tsk types.TipSetKey)
|
|||||||
return c.Internal.MpoolPending(ctx, tsk)
|
return c.Internal.MpoolPending(ctx, tsk)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *FullNodeStruct) MpoolClear(ctx context.Context, localonly bool) error {
|
func (c *FullNodeStruct) MpoolClear(ctx context.Context, local bool) error {
|
||||||
return c.Internal.MpoolClear(ctx, localonly)
|
return c.Internal.MpoolClear(ctx, local)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *FullNodeStruct) MpoolPush(ctx context.Context, smsg *types.SignedMessage) (cid.Cid, error) {
|
func (c *FullNodeStruct) MpoolPush(ctx context.Context, smsg *types.SignedMessage) (cid.Cid, error) {
|
||||||
|
@ -974,11 +974,13 @@ func (mp *MessagePool) loadLocal() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (mp *MessagePool) Clear(localonly bool) {
|
func (mp *MessagePool) Clear(local bool) {
|
||||||
mp.lk.Lock()
|
mp.lk.Lock()
|
||||||
defer mp.lk.Unlock()
|
defer mp.lk.Unlock()
|
||||||
|
|
||||||
// remove local messages from the datastore
|
// remove everything if local is true, including removing local messages from
|
||||||
|
// the datastore
|
||||||
|
if local {
|
||||||
for a := range mp.localAddrs {
|
for a := range mp.localAddrs {
|
||||||
mset, ok := mp.pending[a]
|
mset, ok := mp.pending[a]
|
||||||
if !ok {
|
if !ok {
|
||||||
@ -991,14 +993,20 @@ func (mp *MessagePool) Clear(localonly bool) {
|
|||||||
log.Warnf("error deleting local message: %s", err)
|
log.Warnf("error deleting local message: %s", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
mp.pending = make(map[address.Address]*msgSet)
|
||||||
|
mp.republished = nil
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// remove everything except the local messages
|
||||||
|
for a := range mp.pending {
|
||||||
|
_, isLocal := mp.localAddrs[a]
|
||||||
|
if isLocal {
|
||||||
|
continue
|
||||||
|
}
|
||||||
delete(mp.pending, a)
|
delete(mp.pending, a)
|
||||||
}
|
}
|
||||||
|
|
||||||
// clear the maps
|
|
||||||
mp.republished = nil
|
|
||||||
if !localonly {
|
|
||||||
mp.pending = make(map[address.Address]*msgSet)
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -90,7 +90,7 @@ var mpoolClear = &cli.Command{
|
|||||||
Flags: []cli.Flag{
|
Flags: []cli.Flag{
|
||||||
&cli.BoolFlag{
|
&cli.BoolFlag{
|
||||||
Name: "local",
|
Name: "local",
|
||||||
Usage: "clear local messages only",
|
Usage: "also clear local messages",
|
||||||
},
|
},
|
||||||
&cli.BoolFlag{
|
&cli.BoolFlag{
|
||||||
Name: "really-do-it",
|
Name: "really-do-it",
|
||||||
|
@ -20,7 +20,7 @@ The full node API defines the following methods for interacting with the mpool:
|
|||||||
MpoolSub(context.Context) (<-chan MpoolUpdate, error)
|
MpoolSub(context.Context) (<-chan MpoolUpdate, error)
|
||||||
MpoolGetConfig(context.Context) (*types.MpoolConfig, error)
|
MpoolGetConfig(context.Context) (*types.MpoolConfig, error)
|
||||||
MpoolSetConfig(context.Context, *types.MpoolConfig) error
|
MpoolSetConfig(context.Context, *types.MpoolConfig) error
|
||||||
MpoolClear(context.Context, localonly bool) error
|
MpoolClear(context.Context, local bool) error
|
||||||
```
|
```
|
||||||
|
|
||||||
### MpoolPending
|
### MpoolPending
|
||||||
@ -64,7 +64,7 @@ Sets the mpool configuration to (a copy of) the supplied configuration object.
|
|||||||
|
|
||||||
### MpoolClear
|
### MpoolClear
|
||||||
|
|
||||||
Clears pending messages from the mpool; if `localonly` is `true` then only local messages are cleared.
|
Clears pending messages from the mpool; if `local` is `true` then local messages are also cleared and removed from the datastore.
|
||||||
|
|
||||||
This should be used with extreme care and only in the case of errors during head changes that
|
This should be used with extreme care and only in the case of errors during head changes that
|
||||||
would leave the mpool in an inconsistent state.
|
would leave the mpool in an inconsistent state.
|
||||||
@ -109,11 +109,9 @@ Gets or sets the current mpool configuration.
|
|||||||
|
|
||||||
### lotus mpool clear
|
### lotus mpool clear
|
||||||
Unconditionally clears pending messages from the mpool.
|
Unconditionally clears pending messages from the mpool.
|
||||||
If the `--local` flag is passed, then only local messages are cleared; otherwise all messages
|
If the `--local` flag is passed, then local messages are also cleared; otherwise local messages are retained.
|
||||||
are cleared.
|
|
||||||
|
|
||||||
*Warning*: this command should only be used in the case of head change errors leaving the mpool in an
|
*Warning*: this command should only be used in the case of head change errors leaving the mpool in an state.
|
||||||
inconsistent state.
|
|
||||||
|
|
||||||
## Configuration
|
## Configuration
|
||||||
|
|
||||||
|
@ -105,8 +105,8 @@ func (a *MpoolAPI) MpoolPending(ctx context.Context, tsk types.TipSetKey) ([]*ty
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *MpoolAPI) MpoolClear(ctx context.Context, localonly bool) error {
|
func (a *MpoolAPI) MpoolClear(ctx context.Context, local bool) error {
|
||||||
a.Mpool.Clear(localonly)
|
a.Mpool.Clear(local)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user