forked from TrueCloudLab/frostfs-node
[#1700] engine: Drop unused block execution methods
`BlockExecution` and `ResumeExecution` were used only by unit test. So drop them and simplify code. Change-Id: Ib3de324617e8a27fc1f015542ac5e94df5c60a6e Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
This commit is contained in:
parent
e80632884a
commit
fd37cea443
3 changed files with 10 additions and 102 deletions
|
@ -22,10 +22,6 @@ type shardInitError struct {
|
|||
|
||||
// Open opens all StorageEngine's components.
|
||||
func (e *StorageEngine) Open(ctx context.Context) error {
|
||||
return e.open(ctx)
|
||||
}
|
||||
|
||||
func (e *StorageEngine) open(ctx context.Context) error {
|
||||
e.mtx.Lock()
|
||||
defer e.mtx.Unlock()
|
||||
|
||||
|
@ -149,11 +145,11 @@ var errClosed = errors.New("storage engine is closed")
|
|||
func (e *StorageEngine) Close(ctx context.Context) error {
|
||||
close(e.closeCh)
|
||||
defer e.wg.Wait()
|
||||
return e.setBlockExecErr(ctx, errClosed)
|
||||
return e.closeEngine(ctx)
|
||||
}
|
||||
|
||||
// closes all shards. Never returns an error, shard errors are logged.
|
||||
func (e *StorageEngine) close(ctx context.Context) error {
|
||||
func (e *StorageEngine) closeAllShards(ctx context.Context) error {
|
||||
e.mtx.RLock()
|
||||
defer e.mtx.RUnlock()
|
||||
|
||||
|
@ -176,70 +172,23 @@ func (e *StorageEngine) execIfNotBlocked(op func() error) error {
|
|||
e.blockExec.mtx.RLock()
|
||||
defer e.blockExec.mtx.RUnlock()
|
||||
|
||||
if e.blockExec.err != nil {
|
||||
return e.blockExec.err
|
||||
if e.blockExec.closed {
|
||||
return errClosed
|
||||
}
|
||||
|
||||
return op()
|
||||
}
|
||||
|
||||
// sets the flag of blocking execution of all data operations according to err:
|
||||
// - err != nil, then blocks the execution. If exec wasn't blocked, calls close method
|
||||
// (if err == errClosed => additionally releases pools and does not allow to resume executions).
|
||||
// - otherwise, resumes execution. If exec was blocked, calls open method.
|
||||
//
|
||||
// Can be called concurrently with exec. In this case it waits for all executions to complete.
|
||||
func (e *StorageEngine) setBlockExecErr(ctx context.Context, err error) error {
|
||||
func (e *StorageEngine) closeEngine(ctx context.Context) error {
|
||||
e.blockExec.mtx.Lock()
|
||||
defer e.blockExec.mtx.Unlock()
|
||||
|
||||
prevErr := e.blockExec.err
|
||||
|
||||
wasClosed := errors.Is(prevErr, errClosed)
|
||||
if wasClosed {
|
||||
if e.blockExec.closed {
|
||||
return errClosed
|
||||
}
|
||||
|
||||
e.blockExec.err = err
|
||||
|
||||
if err == nil {
|
||||
if prevErr != nil { // block -> ok
|
||||
return e.open(ctx)
|
||||
}
|
||||
} else if prevErr == nil { // ok -> block
|
||||
return e.close(ctx)
|
||||
}
|
||||
|
||||
// otherwise do nothing
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// BlockExecution blocks the execution of any data-related operation. All blocked ops will return err.
|
||||
// To resume the execution, use ResumeExecution method.
|
||||
//
|
||||
// Сan be called regardless of the fact of the previous blocking. If execution wasn't blocked, releases all resources
|
||||
// similar to Close. Can be called concurrently with Close and any data related method (waits for all executions
|
||||
// to complete). Returns error if any Close has been called before.
|
||||
//
|
||||
// Must not be called concurrently with either Open or Init.
|
||||
//
|
||||
// Note: technically passing nil error will resume the execution, otherwise, it is recommended to call ResumeExecution
|
||||
// for this.
|
||||
func (e *StorageEngine) BlockExecution(err error) error {
|
||||
return e.setBlockExecErr(context.Background(), err)
|
||||
}
|
||||
|
||||
// ResumeExecution resumes the execution of any data-related operation.
|
||||
// To block the execution, use BlockExecution method.
|
||||
//
|
||||
// Сan be called regardless of the fact of the previous blocking. If execution was blocked, prepares all resources
|
||||
// similar to Open. Can be called concurrently with Close and any data related method (waits for all executions
|
||||
// to complete). Returns error if any Close has been called before.
|
||||
//
|
||||
// Must not be called concurrently with either Open or Init.
|
||||
func (e *StorageEngine) ResumeExecution() error {
|
||||
return e.setBlockExecErr(context.Background(), nil)
|
||||
e.blockExec.closed = true
|
||||
return e.closeAllShards(ctx)
|
||||
}
|
||||
|
||||
type ReConfiguration struct {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue