@@ -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,35 +48,10 @@ 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
- // returns BoltDB errors only.
80
- func putMetadataForObject (tx * bbolt.Tx , hdr object.Object , hasParent , phy bool ) error {
51
+ // PutMetadataForObject fills object meta-data indexes using bbolt transaction.
52
+ // Transaction must be writable. Additional bucket for container's meta-data
53
+ // may be created using {255, CID...} form as a key.
54
+ func PutMetadataForObject (tx * bbolt.Tx , hdr object.Object , hasParent , phy bool ) error {
81
55
metaBkt , err := tx .CreateBucketIfNotExists (metaBucketKey (hdr .GetContainerID ()))
82
56
if err != nil {
83
57
return fmt .Errorf ("create meta bucket for container: %w" , err )
@@ -178,21 +152,21 @@ func deleteMetadata(tx *bbolt.Tx, cnr cid.ID, id oid.ID) error {
178
152
pref [0 ] = metaPrefixIDAttr
179
153
c := metaBkt .Cursor ()
180
154
for kIDAttr , _ := c .Seek (pref ); bytes .HasPrefix (kIDAttr , pref ); kIDAttr , _ = c .Next () {
181
- sepInd := bytes .LastIndex (kIDAttr , attributeDelimiter )
155
+ sepInd := bytes .LastIndex (kIDAttr , objectcore . AttributeDelimiter )
182
156
if sepInd < 0 {
183
157
return fmt .Errorf ("invalid key with prefix 0x%X in meta bucket: missing delimiter" , kIDAttr [0 ])
184
158
}
185
159
kAttrID := make ([]byte , len (kIDAttr )+ attributeDelimiterLen )
186
160
kAttrID [0 ] = metaPrefixAttrIDPlain
187
161
off := 1 + copy (kAttrID [1 :], kIDAttr [1 + oid .Size :])
188
- off += copy (kAttrID [off :], attributeDelimiter )
162
+ off += copy (kAttrID [off :], objectcore . AttributeDelimiter )
189
163
copy (kAttrID [off :], id [:])
190
164
ks = append (ks , kIDAttr , kAttrID )
191
165
if n , ok := new (big.Int ).SetString (string (kIDAttr [sepInd + attributeDelimiterLen :]), 10 ); ok && intWithinLimits (n ) {
192
166
kAttrIDInt := make ([]byte , sepInd + attributeDelimiterLen + intValLen )
193
167
kAttrIDInt [0 ] = metaPrefixAttrIDInt
194
168
off := 1 + copy (kAttrIDInt [1 :], kIDAttr [1 + oid .Size :sepInd ])
195
- off += copy (kAttrIDInt [off :], attributeDelimiter )
169
+ off += copy (kAttrIDInt [off :], objectcore . AttributeDelimiter )
196
170
putInt (kAttrIDInt [off :off + intValLen ], n )
197
171
copy (kAttrIDInt [off + intValLen :], id [:])
198
172
ks = append (ks , kAttrIDInt )
@@ -305,7 +279,7 @@ func PreprocessSearchQuery(fs object.SearchFilters, attrs []string, cursor strin
305
279
if ! bytes .Equal (primKeysPrefix [1 :1 + len (attrs [0 ])], []byte (attrs [0 ])) {
306
280
return nil , nil , fmt .Errorf ("%w: %w" , errInvalidCursor , errWrongPrimaryAttribute )
307
281
}
308
- if ! bytes .Equal (primKeysPrefix [1 + len (attrs [0 ]):], attributeDelimiter ) {
282
+ if ! bytes .Equal (primKeysPrefix [1 + len (attrs [0 ]):], objectcore . AttributeDelimiter ) {
309
283
return nil , nil , fmt .Errorf ("%w: %w" , errInvalidCursor , errWrongKeyValDelim )
310
284
}
311
285
if primSeekKey [len (primKeysPrefix )] > 1 {
@@ -319,10 +293,10 @@ func PreprocessSearchQuery(fs object.SearchFilters, attrs []string, cursor strin
319
293
if ! bytes .Equal (primKeysPrefix [1 :1 + len (attrs [0 ])], []byte (attrs [0 ])) {
320
294
return nil , nil , fmt .Errorf ("%w: %w" , errInvalidCursor , errWrongPrimaryAttribute )
321
295
}
322
- if ! bytes .Equal (primKeysPrefix [1 + len (attrs [0 ]):], attributeDelimiter ) {
296
+ if ! bytes .Equal (primKeysPrefix [1 + len (attrs [0 ]):], objectcore . AttributeDelimiter ) {
323
297
return nil , nil , fmt .Errorf ("%w: %w" , errInvalidCursor , errWrongKeyValDelim )
324
298
}
325
- if ! bytes .Equal (primSeekKey [len (primSeekKey )- oid .Size - attributeDelimiterLen :][:attributeDelimiterLen ], attributeDelimiter ) {
299
+ if ! bytes .Equal (primSeekKey [len (primSeekKey )- oid .Size - attributeDelimiterLen :][:attributeDelimiterLen ], objectcore . AttributeDelimiter ) {
326
300
return nil , nil , fmt .Errorf ("%w: %w" , errInvalidCursor , errWrongValOIDDelim )
327
301
}
328
302
}
@@ -352,15 +326,15 @@ func PreprocessSearchQuery(fs object.SearchFilters, attrs []string, cursor strin
352
326
if objectcore .IsIntegerSearchOp (primMatcher ) {
353
327
f := fInt [0 ]
354
328
if ! f .auto && (primMatcher == object .MatchNumGE || primMatcher == object .MatchNumGT ) {
355
- primSeekKey = slices .Concat ([]byte {metaPrefixAttrIDInt }, []byte (attrs [0 ]), attributeDelimiter , f .b )
329
+ primSeekKey = slices .Concat ([]byte {metaPrefixAttrIDInt }, []byte (attrs [0 ]), objectcore . AttributeDelimiter , f .b )
356
330
primKeysPrefix = primSeekKey [:1 + len (attrs [0 ])+ attributeDelimiterLen ]
357
331
} else {
358
- primSeekKey = slices .Concat ([]byte {metaPrefixAttrIDInt }, []byte (attrs [0 ]), attributeDelimiter )
332
+ primSeekKey = slices .Concat ([]byte {metaPrefixAttrIDInt }, []byte (attrs [0 ]), objectcore . AttributeDelimiter )
359
333
primKeysPrefix = primSeekKey
360
334
}
361
335
} else {
362
336
// according to the condition above, primValDB is empty for '!=' matcher as it should be
363
- primSeekKey = slices .Concat ([]byte {metaPrefixAttrIDPlain }, []byte (attrs [0 ]), attributeDelimiter , primValDB )
337
+ primSeekKey = slices .Concat ([]byte {metaPrefixAttrIDPlain }, []byte (attrs [0 ]), objectcore . AttributeDelimiter , primValDB )
364
338
primKeysPrefix = primSeekKey [:1 + len (attrs [0 ])+ attributeDelimiterLen ]
365
339
}
366
340
}
@@ -375,7 +349,7 @@ func splitValOID(b []byte) ([]byte, []byte, error) {
375
349
}
376
350
idOff := len (b ) - oid .Size
377
351
valLn := idOff - attributeDelimiterLen
378
- if ! bytes .Equal (b [valLn :idOff ], attributeDelimiter ) {
352
+ if ! bytes .Equal (b [valLn :idOff ], objectcore . AttributeDelimiter ) {
379
353
return nil , nil , errWrongValOIDDelim
380
354
}
381
355
return b [:valLn ], b [idOff :], nil
@@ -798,11 +772,11 @@ func prepareMetaAttrIDKey(buf *keyBuffer, id oid.ID, attr string, valLen int, in
798
772
k [0 ] = metaPrefixAttrIDPlain
799
773
}
800
774
off := 1 + copy (k [1 :], attr )
801
- off += copy (k [off :], attributeDelimiter )
775
+ off += copy (k [off :], objectcore . AttributeDelimiter )
802
776
valOff := off
803
777
off += valLen
804
778
if ! intAttr {
805
- off += copy (k [off :], attributeDelimiter )
779
+ off += copy (k [off :], objectcore . AttributeDelimiter )
806
780
}
807
781
copy (k [off :], id [:])
808
782
return k , valOff
@@ -814,7 +788,7 @@ func prepareMetaIDAttrKey(buf *keyBuffer, id oid.ID, attr string, valLen int) []
814
788
k [0 ] = metaPrefixIDAttr
815
789
off := 1 + copy (k [1 :], id [:])
816
790
off += copy (k [off :], attr )
817
- copy (k [off :], attributeDelimiter )
791
+ copy (k [off :], objectcore . AttributeDelimiter )
818
792
return k
819
793
}
820
794
@@ -852,7 +826,7 @@ func (x *metaAttributeSeeker) get(id []byte, attr string) ([]byte, error) {
852
826
pref [0 ] = metaPrefixIDAttr
853
827
off := 1 + copy (pref [1 :], id )
854
828
off += copy (pref [off :], attr )
855
- copy (pref [off :], attributeDelimiter )
829
+ copy (pref [off :], objectcore . AttributeDelimiter )
856
830
if x .crsr == nil {
857
831
x .crsr = x .bkt .Cursor ()
858
832
}
@@ -914,7 +888,7 @@ func CalculateCursor(fs object.SearchFilters, lastItem client.SearchResultItem)
914
888
}
915
889
res := make ([]byte , len (attr )+ attributeDelimiterLen + intValLen + oid .Size )
916
890
off := copy (res , attr )
917
- off += copy (res [off :], attributeDelimiter )
891
+ off += copy (res [off :], objectcore . AttributeDelimiter )
918
892
putInt (res [off :off + intValLen ], n )
919
893
copy (res [off + intValLen :], lastItem .ID [:])
920
894
return res , nil
@@ -931,12 +905,12 @@ func CalculateCursor(fs object.SearchFilters, lastItem client.SearchResultItem)
931
905
}
932
906
res := make ([]byte , len (attr )+ attributeDelimiterLen + ln + attributeDelimiterLen + oid .Size )
933
907
off := copy (res , attr )
934
- off += copy (res [off :], attributeDelimiter )
908
+ off += copy (res [off :], objectcore . AttributeDelimiter )
935
909
var err error
936
910
if _ , err = hex .Decode (res [off :], []byte (lastItemVal )); err != nil {
937
911
return nil , fmt .Errorf ("decode %q attribute from HEX: %w" , attr , err )
938
912
}
939
- off += copy (res [off + ln :], attributeDelimiter )
913
+ off += copy (res [off + ln :], objectcore . AttributeDelimiter )
940
914
copy (res [off :], lastItem .ID [:])
941
915
return res , nil
942
916
case object .FilterSplitID :
@@ -953,9 +927,9 @@ func CalculateCursor(fs object.SearchFilters, lastItem client.SearchResultItem)
953
927
kln := len (attr ) + attributeDelimiterLen + len (val ) + attributeDelimiterLen + oid .Size
954
928
res := make ([]byte , kln )
955
929
off := copy (res , attr )
956
- off += copy (res [off :], attributeDelimiter )
930
+ off += copy (res [off :], objectcore . AttributeDelimiter )
957
931
off += copy (res [off :], val )
958
- off += copy (res [off :], attributeDelimiter )
932
+ off += copy (res [off :], objectcore . AttributeDelimiter )
959
933
copy (res [off :], lastItem .ID [:])
960
934
return res , nil
961
935
}
0 commit comments