@@ -10,7 +10,6 @@ import (
10
10
"math/big"
11
11
"slices"
12
12
"strconv"
13
- "strings"
14
13
15
14
"github.com/google/uuid"
16
15
"github.com/mr-tron/base58"
@@ -49,33 +48,6 @@ func invalidMetaBucketKeyErr(key []byte, cause error) error {
49
48
return fmt .Errorf ("invalid meta bucket key (prefix 0x%X): %w" , key [0 ], cause )
50
49
}
51
50
52
- // checks whether given header corresponds to metadata bucket requirements and
53
- // limits.
54
- func verifyHeaderForMetadata (hdr object.Object ) error {
55
- if ln := hdr .HeaderLen (); ln > object .MaxHeaderLen {
56
- return fmt .Errorf ("header len %d exceeds the limit" , ln )
57
- }
58
- if hdr .GetContainerID ().IsZero () {
59
- return fmt .Errorf ("invalid container: %w" , cid .ErrZero )
60
- }
61
- if hdr .Owner ().IsZero () {
62
- return fmt .Errorf ("invalid owner: %w" , user .ErrZeroID )
63
- }
64
- if _ , ok := hdr .PayloadChecksum (); ! ok {
65
- return errors .New ("missing payload checksum" )
66
- }
67
- attrs := hdr .Attributes ()
68
- for i := range attrs {
69
- if strings .IndexByte (attrs [i ].Key (), attributeDelimiter [0 ]) >= 0 {
70
- return fmt .Errorf ("attribute #%d key contains 0x%02X byte used in sep" , i , attributeDelimiter [0 ])
71
- }
72
- if strings .IndexByte (attrs [i ].Value (), attributeDelimiter [0 ]) >= 0 {
73
- return fmt .Errorf ("attribute #%d value contains 0x%02X byte used in sep" , i , attributeDelimiter [0 ])
74
- }
75
- }
76
- return nil
77
- }
78
-
79
51
// PutMetadataForObject fills object meta-data indexes using bbolt transaction.
80
52
// Transaction must be writable. Additional bucket for container's meta-data
81
53
// may be created using {255, CID...} form as a key.
@@ -180,21 +152,21 @@ func deleteMetadata(tx *bbolt.Tx, cnr cid.ID, id oid.ID) error {
180
152
pref [0 ] = metaPrefixIDAttr
181
153
c := metaBkt .Cursor ()
182
154
for kIDAttr , _ := c .Seek (pref ); bytes .HasPrefix (kIDAttr , pref ); kIDAttr , _ = c .Next () {
183
- sepInd := bytes .LastIndex (kIDAttr , attributeDelimiter )
155
+ sepInd := bytes .LastIndex (kIDAttr , objectcore . AttributeDelimiter )
184
156
if sepInd < 0 {
185
157
return fmt .Errorf ("invalid key with prefix 0x%X in meta bucket: missing delimiter" , kIDAttr [0 ])
186
158
}
187
159
kAttrID := make ([]byte , len (kIDAttr )+ attributeDelimiterLen )
188
160
kAttrID [0 ] = metaPrefixAttrIDPlain
189
161
off := 1 + copy (kAttrID [1 :], kIDAttr [1 + oid .Size :])
190
- off += copy (kAttrID [off :], attributeDelimiter )
162
+ off += copy (kAttrID [off :], objectcore . AttributeDelimiter )
191
163
copy (kAttrID [off :], id [:])
192
164
ks = append (ks , kIDAttr , kAttrID )
193
165
if n , ok := new (big.Int ).SetString (string (kIDAttr [sepInd + attributeDelimiterLen :]), 10 ); ok && intWithinLimits (n ) {
194
166
kAttrIDInt := make ([]byte , sepInd + attributeDelimiterLen + intValLen )
195
167
kAttrIDInt [0 ] = metaPrefixAttrIDInt
196
168
off := 1 + copy (kAttrIDInt [1 :], kIDAttr [1 + oid .Size :sepInd ])
197
- off += copy (kAttrIDInt [off :], attributeDelimiter )
169
+ off += copy (kAttrIDInt [off :], objectcore . AttributeDelimiter )
198
170
putInt (kAttrIDInt [off :off + intValLen ], n )
199
171
copy (kAttrIDInt [off + intValLen :], id [:])
200
172
ks = append (ks , kAttrIDInt )
@@ -307,7 +279,7 @@ func PreprocessSearchQuery(fs object.SearchFilters, attrs []string, cursor strin
307
279
if ! bytes .Equal (primKeysPrefix [1 :1 + len (attrs [0 ])], []byte (attrs [0 ])) {
308
280
return nil , nil , fmt .Errorf ("%w: %w" , errInvalidCursor , errWrongPrimaryAttribute )
309
281
}
310
- if ! bytes .Equal (primKeysPrefix [1 + len (attrs [0 ]):], attributeDelimiter ) {
282
+ if ! bytes .Equal (primKeysPrefix [1 + len (attrs [0 ]):], objectcore . AttributeDelimiter ) {
311
283
return nil , nil , fmt .Errorf ("%w: %w" , errInvalidCursor , errWrongKeyValDelim )
312
284
}
313
285
if primSeekKey [len (primKeysPrefix )] > 1 {
@@ -321,10 +293,10 @@ func PreprocessSearchQuery(fs object.SearchFilters, attrs []string, cursor strin
321
293
if ! bytes .Equal (primKeysPrefix [1 :1 + len (attrs [0 ])], []byte (attrs [0 ])) {
322
294
return nil , nil , fmt .Errorf ("%w: %w" , errInvalidCursor , errWrongPrimaryAttribute )
323
295
}
324
- if ! bytes .Equal (primKeysPrefix [1 + len (attrs [0 ]):], attributeDelimiter ) {
296
+ if ! bytes .Equal (primKeysPrefix [1 + len (attrs [0 ]):], objectcore . AttributeDelimiter ) {
325
297
return nil , nil , fmt .Errorf ("%w: %w" , errInvalidCursor , errWrongKeyValDelim )
326
298
}
327
- if ! bytes .Equal (primSeekKey [len (primSeekKey )- oid .Size - attributeDelimiterLen :][:attributeDelimiterLen ], attributeDelimiter ) {
299
+ if ! bytes .Equal (primSeekKey [len (primSeekKey )- oid .Size - attributeDelimiterLen :][:attributeDelimiterLen ], objectcore . AttributeDelimiter ) {
328
300
return nil , nil , fmt .Errorf ("%w: %w" , errInvalidCursor , errWrongValOIDDelim )
329
301
}
330
302
}
@@ -354,15 +326,15 @@ func PreprocessSearchQuery(fs object.SearchFilters, attrs []string, cursor strin
354
326
if objectcore .IsIntegerSearchOp (primMatcher ) {
355
327
f := fInt [0 ]
356
328
if ! f .auto && (primMatcher == object .MatchNumGE || primMatcher == object .MatchNumGT ) {
357
- primSeekKey = slices .Concat ([]byte {metaPrefixAttrIDInt }, []byte (attrs [0 ]), attributeDelimiter , f .b )
329
+ primSeekKey = slices .Concat ([]byte {metaPrefixAttrIDInt }, []byte (attrs [0 ]), objectcore . AttributeDelimiter , f .b )
358
330
primKeysPrefix = primSeekKey [:1 + len (attrs [0 ])+ attributeDelimiterLen ]
359
331
} else {
360
- primSeekKey = slices .Concat ([]byte {metaPrefixAttrIDInt }, []byte (attrs [0 ]), attributeDelimiter )
332
+ primSeekKey = slices .Concat ([]byte {metaPrefixAttrIDInt }, []byte (attrs [0 ]), objectcore . AttributeDelimiter )
361
333
primKeysPrefix = primSeekKey
362
334
}
363
335
} else {
364
336
// according to the condition above, primValDB is empty for '!=' matcher as it should be
365
- primSeekKey = slices .Concat ([]byte {metaPrefixAttrIDPlain }, []byte (attrs [0 ]), attributeDelimiter , primValDB )
337
+ primSeekKey = slices .Concat ([]byte {metaPrefixAttrIDPlain }, []byte (attrs [0 ]), objectcore . AttributeDelimiter , primValDB )
366
338
primKeysPrefix = primSeekKey [:1 + len (attrs [0 ])+ attributeDelimiterLen ]
367
339
}
368
340
}
@@ -377,7 +349,7 @@ func splitValOID(b []byte) ([]byte, []byte, error) {
377
349
}
378
350
idOff := len (b ) - oid .Size
379
351
valLn := idOff - attributeDelimiterLen
380
- if ! bytes .Equal (b [valLn :idOff ], attributeDelimiter ) {
352
+ if ! bytes .Equal (b [valLn :idOff ], objectcore . AttributeDelimiter ) {
381
353
return nil , nil , errWrongValOIDDelim
382
354
}
383
355
return b [:valLn ], b [idOff :], nil
@@ -800,11 +772,11 @@ func prepareMetaAttrIDKey(buf *keyBuffer, id oid.ID, attr string, valLen int, in
800
772
k [0 ] = metaPrefixAttrIDPlain
801
773
}
802
774
off := 1 + copy (k [1 :], attr )
803
- off += copy (k [off :], attributeDelimiter )
775
+ off += copy (k [off :], objectcore . AttributeDelimiter )
804
776
valOff := off
805
777
off += valLen
806
778
if ! intAttr {
807
- off += copy (k [off :], attributeDelimiter )
779
+ off += copy (k [off :], objectcore . AttributeDelimiter )
808
780
}
809
781
copy (k [off :], id [:])
810
782
return k , valOff
@@ -816,7 +788,7 @@ func prepareMetaIDAttrKey(buf *keyBuffer, id oid.ID, attr string, valLen int) []
816
788
k [0 ] = metaPrefixIDAttr
817
789
off := 1 + copy (k [1 :], id [:])
818
790
off += copy (k [off :], attr )
819
- copy (k [off :], attributeDelimiter )
791
+ copy (k [off :], objectcore . AttributeDelimiter )
820
792
return k
821
793
}
822
794
@@ -854,7 +826,7 @@ func (x *metaAttributeSeeker) get(id []byte, attr string) ([]byte, error) {
854
826
pref [0 ] = metaPrefixIDAttr
855
827
off := 1 + copy (pref [1 :], id )
856
828
off += copy (pref [off :], attr )
857
- copy (pref [off :], attributeDelimiter )
829
+ copy (pref [off :], objectcore . AttributeDelimiter )
858
830
if x .crsr == nil {
859
831
x .crsr = x .bkt .Cursor ()
860
832
}
@@ -916,7 +888,7 @@ func CalculateCursor(fs object.SearchFilters, lastItem client.SearchResultItem)
916
888
}
917
889
res := make ([]byte , len (attr )+ attributeDelimiterLen + intValLen + oid .Size )
918
890
off := copy (res , attr )
919
- off += copy (res [off :], attributeDelimiter )
891
+ off += copy (res [off :], objectcore . AttributeDelimiter )
920
892
putInt (res [off :off + intValLen ], n )
921
893
copy (res [off + intValLen :], lastItem .ID [:])
922
894
return res , nil
@@ -933,12 +905,12 @@ func CalculateCursor(fs object.SearchFilters, lastItem client.SearchResultItem)
933
905
}
934
906
res := make ([]byte , len (attr )+ attributeDelimiterLen + ln + attributeDelimiterLen + oid .Size )
935
907
off := copy (res , attr )
936
- off += copy (res [off :], attributeDelimiter )
908
+ off += copy (res [off :], objectcore . AttributeDelimiter )
937
909
var err error
938
910
if _ , err = hex .Decode (res [off :], []byte (lastItemVal )); err != nil {
939
911
return nil , fmt .Errorf ("decode %q attribute from HEX: %w" , attr , err )
940
912
}
941
- off += copy (res [off + ln :], attributeDelimiter )
913
+ off += copy (res [off + ln :], objectcore . AttributeDelimiter )
942
914
copy (res [off :], lastItem .ID [:])
943
915
return res , nil
944
916
case object .FilterSplitID :
@@ -955,9 +927,9 @@ func CalculateCursor(fs object.SearchFilters, lastItem client.SearchResultItem)
955
927
kln := len (attr ) + attributeDelimiterLen + len (val ) + attributeDelimiterLen + oid .Size
956
928
res := make ([]byte , kln )
957
929
off := copy (res , attr )
958
- off += copy (res [off :], attributeDelimiter )
930
+ off += copy (res [off :], objectcore . AttributeDelimiter )
959
931
off += copy (res [off :], val )
960
- off += copy (res [off :], attributeDelimiter )
932
+ off += copy (res [off :], objectcore . AttributeDelimiter )
961
933
copy (res [off :], lastItem .ID [:])
962
934
return res , nil
963
935
}
0 commit comments