diff --git a/pkg/linedb/line_db.go b/pkg/linedb/line_db.go index 7864415..5df63ed 100644 --- a/pkg/linedb/line_db.go +++ b/pkg/linedb/line_db.go @@ -88,6 +88,8 @@ func (db *LineDb) Init(force bool, initOptions *LineDbInitOptions) error { if dbFolder == "" { dbFolder = "linedb" } + // Нормализуем и сохраняем фактический путь, чтобы партиции создавались в той же папке + db.initOptions.DBFolder = dbFolder if err := os.MkdirAll(dbFolder, 0755); err != nil { return fmt.Errorf("failed to create database folder: %w", err) @@ -229,7 +231,13 @@ func (db *LineDb) seedLastIDPartitioned(dbFolder, baseName string) error { if existing, ok := db.adapters[partName]; ok { adapter = existing } else { - adapter = NewJSONLFile(path, "", JSONLFileOptions{CollectionName: partName}) + // Партиции должны наследовать опции базовой коллекции (allocSize/encode/crypto/marshal/etc.) + opts := JSONLFileOptions{CollectionName: partName} + if baseOpts := db.getCollectionOptions(baseName); baseOpts != nil { + opts = *baseOpts + opts.CollectionName = partName + } + adapter = NewJSONLFile(path, opts.EncryptKeyForLineDb, opts) if err := adapter.Init(false, LineDbAdapterOptions{}); err != nil { continue } @@ -655,7 +663,7 @@ func (db *LineDb) ReadByFilter(filter any, collectionName string, options LineDb if err != nil || (options.FailOnFailureIndexRead && !hit) { return nil, fmt.Errorf("index read failed: %w", err) } - if hit && err == nil { + if hit { if db.cacheExternal != nil && !options.InTransaction { db.cacheExternal.Set(db.generateCacheKey(filter, collectionName), result) } @@ -686,7 +694,7 @@ func (db *LineDb) ReadByFilter(filter any, collectionName string, options LineDb if err != nil || (options.FailOnFailureIndexRead && !hit) { return nil, fmt.Errorf("index read failed: %w", err) } - if hit && err == nil { + if hit { if db.cacheExternal != nil && !options.InTransaction { db.cacheExternal.Set(db.generateCacheKey(filter, collectionName), result) } @@ -1148,7 +1156,7 @@ func (db *LineDb) getCollectionOptions(collectionName string) *JSONLFileOptions } // isValueEmpty проверяет, считается ли значение "пустым" (nil или "" для string) — для обратной совместимости -func (db *LineDb) isValueEmpty(v any) bool { +func (db *LineDb) IsValueEmpty(v any) bool { if v == nil { return true } @@ -1386,7 +1394,13 @@ func (db *LineDb) getPartitionAdapter(data any, collectionName string) (*JSONLFi if !exists { // Создаем новый адаптер для партиции filename := filepath.Join(db.initOptions.DBFolder, partitionName+".jsonl") - adapter = NewJSONLFile(filename, "", JSONLFileOptions{CollectionName: partitionName}) + // Партиции должны наследовать опции базовой коллекции (allocSize/encode/crypto/marshal/etc.) + opts := JSONLFileOptions{CollectionName: partitionName} + if baseOpts := db.getCollectionOptions(collectionName); baseOpts != nil { + opts = *baseOpts + opts.CollectionName = partitionName + } + adapter = NewJSONLFile(filename, opts.EncryptKeyForLineDb, opts) if err := adapter.Init(false, LineDbAdapterOptions{}); err != nil { return nil, fmt.Errorf("failed to init partition adapter: %w", err)