Skip to content

Commit 2d3cdb5

Browse files
Minor refactoring in storage DELETE (#3571)
2 parents 64c8ca9 + 6625a8d commit 2d3cdb5

File tree

1 file changed

+25
-33
lines changed

1 file changed

+25
-33
lines changed

pkg/local_object_storage/engine/inhume.go

Lines changed: 25 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,10 @@ func (e *StorageEngine) inhume(addrs []oid.Address, force bool, tombstone *oid.A
5151
}
5252
}
5353

54-
ok, err := e.inhumeAddr(addrs[i], force, tombstone, tombExpiration)
54+
err := e.inhumeAddr(addrs[i], force, tombstone, tombExpiration)
5555
if err != nil {
5656
return err
5757
}
58-
if !ok {
59-
return errInhumeFailure
60-
}
6158
}
6259

6360
return nil
@@ -90,12 +87,11 @@ func (e *StorageEngine) InhumeContainer(cID cid.ID) error {
9087
}
9188

9289
// Returns ok if object was inhumed during this invocation or before.
93-
func (e *StorageEngine) inhumeAddr(addr oid.Address, force bool, tombstone *oid.Address, tombExpiration uint64) (bool, error) {
90+
func (e *StorageEngine) inhumeAddr(addr oid.Address, force bool, tombstone *oid.Address, tombExpiration uint64) error {
9491
var (
95-
children []oid.Address
96-
err error
97-
root bool
98-
shardWithObject string
92+
children []oid.Address
93+
err error
94+
root bool
9995
)
10096

10197
// see if the object is root
@@ -106,9 +102,9 @@ func (e *StorageEngine) inhumeAddr(addr oid.Address, force bool, tombstone *oid.
106102
continue
107103
}
108104

109-
if shard.IsErrRemoved(err) || shard.IsErrObjectExpired(err) {
105+
if shard.IsErrRemoved(err) {
110106
// inhumed once - no need to be inhumed again
111-
return true, nil
107+
return nil
112108
}
113109

114110
var siErr *objectSDK.SplitInfoError
@@ -141,7 +137,7 @@ func (e *StorageEngine) inhumeAddr(addr oid.Address, force bool, tombstone *oid.
141137

142138
// nothing can be done here, so just returning ok
143139
// to continue handling other addresses
144-
return true, nil
140+
return nil
145141
}
146142

147143
// v2 split
@@ -156,7 +152,7 @@ func (e *StorageEngine) inhumeAddr(addr oid.Address, force bool, tombstone *oid.
156152

157153
// nothing can be done here, so just returning ok
158154
// to continue handling other addresses
159-
return true, nil
155+
return nil
160156
}
161157

162158
children = measuredObjsToAddresses(addr.Container(), link.Objects())
@@ -170,35 +166,27 @@ func (e *StorageEngine) inhumeAddr(addr oid.Address, force bool, tombstone *oid.
170166
break
171167
}
172168

173-
if exists {
174-
shardWithObject = sh.ID().String()
175-
break
169+
if !exists {
170+
continue
176171
}
177-
}
178-
179-
var addrs = append(children, addr)
180-
181-
if shardWithObject != "" {
182-
sh := e.getShard(shardWithObject)
183172

184173
if tombstone != nil {
185-
err = sh.Inhume(*tombstone, tombExpiration, addrs...)
174+
err = sh.Inhume(*tombstone, tombExpiration, addr)
186175
} else {
187-
err = sh.MarkGarbage(force, addrs...)
176+
err = sh.MarkGarbage(force, addr)
188177
}
189178

190179
if err != nil {
191180
if !errors.Is(err, logicerr.Error) {
192181
e.reportShardError(sh, "could not inhume object in shard", err, zap.Stringer("addr", addr))
193182
}
194-
195-
return false, err
196183
}
197184

198-
return true, nil
185+
return err
199186
}
200187

201188
var (
189+
addrs = append(children, addr)
202190
ok bool
203191
retErr error
204192
)
@@ -215,28 +203,32 @@ func (e *StorageEngine) inhumeAddr(addr oid.Address, force bool, tombstone *oid.
215203

216204
switch {
217205
case errors.As(err, &errLocked):
218-
return false, apistatus.ObjectLocked{} // Always a final error if returned.
206+
return apistatus.ObjectLocked{} // Always a final error if returned.
219207
case errors.Is(err, shard.ErrLockObjectRemoval):
220-
return false, meta.ErrLockObjectRemoval // Always a final error if returned.
208+
return meta.ErrLockObjectRemoval // Always a final error if returned.
221209
case errors.Is(err, shard.ErrReadOnlyMode) || errors.Is(err, shard.ErrDegradedMode):
222210
if root {
223211
retErr = err
224212
continue
225213
}
226-
return false, err
214+
return err
227215
}
228216

229217
e.reportShardError(sh, "could not inhume object in shard", err, zap.Stringer("addr", addr))
230218
continue
231219
}
232220

233-
ok = true
234221
if !root {
235-
break
222+
return nil
236223
}
224+
225+
ok = true
237226
}
238227

239-
return ok, retErr
228+
if retErr == nil && !ok {
229+
retErr = errInhumeFailure
230+
}
231+
return retErr
240232
}
241233

242234
// IsLocked checks whether an object is locked according to StorageEngine's state.

0 commit comments

Comments
 (0)