finish index feature
This commit is contained in:
@@ -6,26 +6,37 @@ import (
|
||||
"sync"
|
||||
)
|
||||
|
||||
// IndexPosition — позиция записи в индексе (партиция + номер строки).
|
||||
// Partition "default" — для обычных коллекций без партиционирования.
|
||||
type IndexPosition struct {
|
||||
Partition string // имя партиции ("default" для обычных коллекций)
|
||||
LineIndex int
|
||||
}
|
||||
|
||||
// DefaultPartition — значение партиции для непартиционированных коллекций.
|
||||
const DefaultPartition = "default"
|
||||
|
||||
// IndexStore — интерфейс хранилища индексов.
|
||||
// Позволяет подключать разные реализации: в памяти, memcached и др.
|
||||
// Индекс привязан к логической коллекции; для партиционированных хранит (partition, lineIndex).
|
||||
type IndexStore interface {
|
||||
// Lookup ищет позиции записей по полю и значению.
|
||||
// value — строковое представление (см. valueToIndexKey).
|
||||
// Возвращает срез индексов строк (0-based) или nil, nil,
|
||||
// если индекс не используется или записей нет.
|
||||
Lookup(collection, field, value string) ([]int, error)
|
||||
// Возвращает (partition, lineIndex) — для непартиционированных partition = DefaultPartition.
|
||||
Lookup(collection, field, value string) ([]IndexPosition, error)
|
||||
|
||||
// IndexRecord добавляет одну запись в индекс по номеру строки (для точечных Update).
|
||||
IndexRecord(collection string, fields []string, record map[string]any, lineIndex int)
|
||||
// IndexRecord добавляет одну запись в индекс.
|
||||
// partition — имя партиции (DefaultPartition для обычных коллекций).
|
||||
IndexRecord(collection, partition string, fields []string, record map[string]any, lineIndex int)
|
||||
|
||||
// UnindexRecord удаляет одну запись из индекса по номеру строки.
|
||||
UnindexRecord(collection string, fields []string, record map[string]any, lineIndex int)
|
||||
// UnindexRecord удаляет одну запись из индекса.
|
||||
UnindexRecord(collection, partition string, fields []string, record map[string]any, lineIndex int)
|
||||
|
||||
// Rebuild полностью перестраивает индекс коллекции.
|
||||
// records — полный список записей, каждая позиция в срезе соответствует номеру строки в файле.
|
||||
Rebuild(collection string, fields []string, records []any) error
|
||||
// Rebuild перестраивает вклад в индекс для одной партиции (или всей коллекции, если одна партиция).
|
||||
// partition — имя партиции; records — записи, позиция в срезе = lineIndex.
|
||||
Rebuild(collection, partition string, fields []string, records []any) error
|
||||
|
||||
// Clear очищает индекс коллекции.
|
||||
// Clear очищает индекс коллекции (все партиции).
|
||||
Clear(collection string) error
|
||||
}
|
||||
|
||||
@@ -65,14 +76,14 @@ func getFieldValue(record map[string]any, field string) string {
|
||||
// InMemoryIndexStore — реализация IndexStore в памяти (по умолчанию).
|
||||
type InMemoryIndexStore struct {
|
||||
mu sync.RWMutex
|
||||
// index: collection:field -> value -> список индексов строк (0-based)
|
||||
index map[string]map[string][]int
|
||||
// index: collection:field -> value -> []IndexPosition
|
||||
index map[string]map[string][]IndexPosition
|
||||
}
|
||||
|
||||
// NewInMemoryIndexStore создаёт новый in-memory индекс.
|
||||
func NewInMemoryIndexStore() *InMemoryIndexStore {
|
||||
return &InMemoryIndexStore{
|
||||
index: make(map[string]map[string][]int),
|
||||
index: make(map[string]map[string][]IndexPosition),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -82,27 +93,33 @@ func (s *InMemoryIndexStore) indexKey(collection, field string) string {
|
||||
}
|
||||
|
||||
// IndexRecord добавляет запись в индекс.
|
||||
func (s *InMemoryIndexStore) IndexRecord(collection string, fields []string, record map[string]any, lineIndex int) {
|
||||
func (s *InMemoryIndexStore) IndexRecord(collection, partition string, fields []string, record map[string]any, lineIndex int) {
|
||||
if len(fields) == 0 || record == nil {
|
||||
return
|
||||
}
|
||||
if partition == "" {
|
||||
partition = DefaultPartition
|
||||
}
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
for _, field := range fields {
|
||||
val := getFieldValue(record, field)
|
||||
key := s.indexKey(collection, field)
|
||||
if s.index[key] == nil {
|
||||
s.index[key] = make(map[string][]int)
|
||||
s.index[key] = make(map[string][]IndexPosition)
|
||||
}
|
||||
s.index[key][val] = append(s.index[key][val], lineIndex)
|
||||
s.index[key][val] = append(s.index[key][val], IndexPosition{Partition: partition, LineIndex: lineIndex})
|
||||
}
|
||||
}
|
||||
|
||||
// UnindexRecord удаляет запись из индекса.
|
||||
func (s *InMemoryIndexStore) UnindexRecord(collection string, fields []string, record map[string]any, lineIndex int) {
|
||||
// UnindexRecord удаляет запись из индекса (по partition и lineIndex).
|
||||
func (s *InMemoryIndexStore) UnindexRecord(collection, partition string, fields []string, record map[string]any, lineIndex int) {
|
||||
if len(fields) == 0 || record == nil {
|
||||
return
|
||||
}
|
||||
if partition == "" {
|
||||
partition = DefaultPartition
|
||||
}
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
for _, field := range fields {
|
||||
@@ -112,23 +129,23 @@ func (s *InMemoryIndexStore) UnindexRecord(collection string, fields []string, r
|
||||
if bucket == nil {
|
||||
continue
|
||||
}
|
||||
idxs := bucket[val]
|
||||
newIdxs := make([]int, 0, len(idxs))
|
||||
for _, i := range idxs {
|
||||
if i != lineIndex {
|
||||
newIdxs = append(newIdxs, i)
|
||||
positions := bucket[val]
|
||||
newPos := make([]IndexPosition, 0, len(positions))
|
||||
for _, p := range positions {
|
||||
if p.Partition != partition || p.LineIndex != lineIndex {
|
||||
newPos = append(newPos, p)
|
||||
}
|
||||
}
|
||||
if len(newIdxs) == 0 {
|
||||
if len(newPos) == 0 {
|
||||
delete(bucket, val)
|
||||
} else {
|
||||
bucket[val] = newIdxs
|
||||
bucket[val] = newPos
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Lookup возвращает индексы строк по полю и значению.
|
||||
func (s *InMemoryIndexStore) Lookup(collection, field, value string) ([]int, error) {
|
||||
// Lookup возвращает позиции (partition, lineIndex) по полю и значению.
|
||||
func (s *InMemoryIndexStore) Lookup(collection, field, value string) ([]IndexPosition, error) {
|
||||
s.mu.RLock()
|
||||
defer s.mu.RUnlock()
|
||||
|
||||
@@ -137,27 +154,46 @@ func (s *InMemoryIndexStore) Lookup(collection, field, value string) ([]int, err
|
||||
if bucket == nil {
|
||||
return nil, nil
|
||||
}
|
||||
indexes := bucket[value]
|
||||
if len(indexes) == 0 {
|
||||
positions := bucket[value]
|
||||
if len(positions) == 0 {
|
||||
return nil, nil
|
||||
}
|
||||
// Возвращаем копию, чтобы вызывающий код не модифицировал внутренний срез
|
||||
out := make([]int, len(indexes))
|
||||
copy(out, indexes)
|
||||
out := make([]IndexPosition, len(positions))
|
||||
copy(out, positions)
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// Rebuild полностью перестраивает индекс коллекции.
|
||||
func (s *InMemoryIndexStore) Rebuild(collection string, fields []string, records []any) error {
|
||||
// Rebuild перестраивает вклад партиции в индекс.
|
||||
func (s *InMemoryIndexStore) Rebuild(collection, partition string, fields []string, records []any) error {
|
||||
if partition == "" {
|
||||
partition = DefaultPartition
|
||||
}
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
|
||||
// Очищаем старые записи по этой коллекции
|
||||
// Удаляем старые позиции этой партиции из индекса
|
||||
for _, field := range fields {
|
||||
key := s.indexKey(collection, field)
|
||||
delete(s.index, key)
|
||||
bucket := s.index[key]
|
||||
if bucket == nil {
|
||||
continue
|
||||
}
|
||||
for val, positions := range bucket {
|
||||
newPos := make([]IndexPosition, 0, len(positions))
|
||||
for _, p := range positions {
|
||||
if p.Partition != partition {
|
||||
newPos = append(newPos, p)
|
||||
}
|
||||
}
|
||||
if len(newPos) == 0 {
|
||||
delete(bucket, val)
|
||||
} else {
|
||||
bucket[val] = newPos
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Добавляем новые позиции
|
||||
for idx, rec := range records {
|
||||
recMap, ok := rec.(map[string]any)
|
||||
if !ok {
|
||||
@@ -167,9 +203,9 @@ func (s *InMemoryIndexStore) Rebuild(collection string, fields []string, records
|
||||
val := getFieldValue(recMap, field)
|
||||
key := s.indexKey(collection, field)
|
||||
if s.index[key] == nil {
|
||||
s.index[key] = make(map[string][]int)
|
||||
s.index[key] = make(map[string][]IndexPosition)
|
||||
}
|
||||
s.index[key][val] = append(s.index[key][val], idx)
|
||||
s.index[key][val] = append(s.index[key][val], IndexPosition{Partition: partition, LineIndex: idx})
|
||||
}
|
||||
}
|
||||
return nil
|
||||
@@ -190,7 +226,7 @@ func (s *InMemoryIndexStore) Clear(collection string) error {
|
||||
}
|
||||
|
||||
// GetSnapshotForTest возвращает копию индекса для тестов. Доступ только при accessKey == "give_me_cache".
|
||||
// Ключ — "collection:field", значение — map[string][]int (значение поля -> номера строк).
|
||||
// Ключ — "collection:field", значение — map[string][]IndexPosition.
|
||||
func (s *InMemoryIndexStore) GetSnapshotForTest(accessKey string) map[string]any {
|
||||
const testAccessKey = "give_me_cache"
|
||||
if accessKey != testAccessKey {
|
||||
@@ -200,11 +236,11 @@ func (s *InMemoryIndexStore) GetSnapshotForTest(accessKey string) map[string]any
|
||||
defer s.mu.RUnlock()
|
||||
out := make(map[string]any, len(s.index))
|
||||
for k, bucket := range s.index {
|
||||
cp := make(map[string][]int, len(bucket))
|
||||
for val, idxs := range bucket {
|
||||
idxs2 := make([]int, len(idxs))
|
||||
copy(idxs2, idxs)
|
||||
cp[val] = idxs2
|
||||
cp := make(map[string][]IndexPosition, len(bucket))
|
||||
for val, positions := range bucket {
|
||||
pos2 := make([]IndexPosition, len(positions))
|
||||
copy(pos2, positions)
|
||||
cp[val] = pos2
|
||||
}
|
||||
out[k] = cp
|
||||
}
|
||||
|
||||
@@ -58,18 +58,22 @@ func (s *MemcachedIndexStore) memKey(collection, field, value string) string {
|
||||
}
|
||||
|
||||
// IndexRecord добавляет запись в индекс.
|
||||
func (s *MemcachedIndexStore) IndexRecord(collection string, fields []string, record map[string]any, lineIndex int) {
|
||||
func (s *MemcachedIndexStore) IndexRecord(collection, partition string, fields []string, record map[string]any, lineIndex int) {
|
||||
if len(fields) == 0 || record == nil {
|
||||
return
|
||||
}
|
||||
if partition == "" {
|
||||
partition = DefaultPartition
|
||||
}
|
||||
pos := IndexPosition{Partition: partition, LineIndex: lineIndex}
|
||||
for _, field := range fields {
|
||||
val := getFieldValue(record, field)
|
||||
key := s.memKey(collection, field, val)
|
||||
var list []int
|
||||
var list []IndexPosition
|
||||
if data, err := s.client.Get(key); err == nil && len(data) > 0 {
|
||||
_ = json.Unmarshal(data, &list)
|
||||
}
|
||||
list = append(list, lineIndex)
|
||||
list = append(list, pos)
|
||||
if data, err := json.Marshal(list); err == nil {
|
||||
_ = s.client.Set(key, data, s.expireSec)
|
||||
}
|
||||
@@ -77,10 +81,13 @@ func (s *MemcachedIndexStore) IndexRecord(collection string, fields []string, re
|
||||
}
|
||||
|
||||
// UnindexRecord удаляет запись из индекса.
|
||||
func (s *MemcachedIndexStore) UnindexRecord(collection string, fields []string, record map[string]any, lineIndex int) {
|
||||
func (s *MemcachedIndexStore) UnindexRecord(collection, partition string, fields []string, record map[string]any, lineIndex int) {
|
||||
if len(fields) == 0 || record == nil {
|
||||
return
|
||||
}
|
||||
if partition == "" {
|
||||
partition = DefaultPartition
|
||||
}
|
||||
for _, field := range fields {
|
||||
val := getFieldValue(record, field)
|
||||
key := s.memKey(collection, field, val)
|
||||
@@ -88,14 +95,14 @@ func (s *MemcachedIndexStore) UnindexRecord(collection string, fields []string,
|
||||
if err != nil || len(data) == 0 {
|
||||
continue
|
||||
}
|
||||
var list []int
|
||||
var list []IndexPosition
|
||||
if json.Unmarshal(data, &list) != nil {
|
||||
continue
|
||||
}
|
||||
var newList []int
|
||||
for _, i := range list {
|
||||
if i != lineIndex {
|
||||
newList = append(newList, i)
|
||||
var newList []IndexPosition
|
||||
for _, p := range list {
|
||||
if p.Partition != partition || p.LineIndex != lineIndex {
|
||||
newList = append(newList, p)
|
||||
}
|
||||
}
|
||||
if len(newList) == 0 {
|
||||
@@ -106,8 +113,8 @@ func (s *MemcachedIndexStore) UnindexRecord(collection string, fields []string,
|
||||
}
|
||||
}
|
||||
|
||||
// Lookup ищет индексы строк по полю и значению.
|
||||
func (s *MemcachedIndexStore) Lookup(collection, field, value string) ([]int, error) {
|
||||
// Lookup ищет позиции по полю и значению.
|
||||
func (s *MemcachedIndexStore) Lookup(collection, field, value string) ([]IndexPosition, error) {
|
||||
key := s.memKey(collection, field, value)
|
||||
data, err := s.client.Get(key)
|
||||
if err != nil {
|
||||
@@ -116,27 +123,38 @@ func (s *MemcachedIndexStore) Lookup(collection, field, value string) ([]int, er
|
||||
if len(data) == 0 {
|
||||
return nil, nil
|
||||
}
|
||||
var indexes []int
|
||||
if json.Unmarshal(data, &indexes) != nil {
|
||||
var positions []IndexPosition
|
||||
if json.Unmarshal(data, &positions) != nil {
|
||||
return nil, nil
|
||||
}
|
||||
// Возвращаем копию, чтобы вызывающий код не модифицировал внутренний срез
|
||||
out := make([]int, len(indexes))
|
||||
copy(out, indexes)
|
||||
out := make([]IndexPosition, len(positions))
|
||||
copy(out, positions)
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// Rebuild перестраивает индекс коллекции (удаляет старые ключи по префиксу и записывает новые).
|
||||
func (s *MemcachedIndexStore) Rebuild(collection string, fields []string, records []any) error {
|
||||
// Rebuild перестраивает вклад партиции в индекс.
|
||||
func (s *MemcachedIndexStore) Rebuild(collection, partition string, fields []string, records []any) error {
|
||||
if partition == "" {
|
||||
partition = DefaultPartition
|
||||
}
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
|
||||
// Memcached не поддерживает перечисление ключей по шаблону.
|
||||
// Стратегия: перезаписываем все ключи для текущих записей.
|
||||
// Старые ключи с другими значениями останутся до TTL.
|
||||
|
||||
// Строим value -> []lineIndex для каждого поля
|
||||
byFieldValue := make(map[string]map[string][]int)
|
||||
// Memcached не поддерживает удаление по паттерну — добавляем новые ключи.
|
||||
// Для корректной замены партиции нужно слить с существующими: получить старые списки,
|
||||
// удалить позиции с Partition==partition, добавить новые. Упрощённо: строим value -> []IndexPosition
|
||||
// только для этой партиции и перезаписываем. Но тогда старые позиции других партиций
|
||||
// для того же value будут потеряны. Поэтому нужен merge: Get, фильтровать по partition, добавлять новые.
|
||||
// Для merge нужен список всех values — его нет. Реалистично: Rebuild вызывается для одной партиции,
|
||||
// и мы должны merge. Без перечисления ключей в Memcached merge невозможен.
|
||||
// Вариант: храним в одном ключе все позиции. При Rebuild(partition) нам нужны ВСЕ ключи
|
||||
// collection:field:value. Их мы не знаем. Прагматичное решение: Rebuild для Memcached
|
||||
// делает полную перезапись для этого partition — мы не можем удалить старые, просто добавляем.
|
||||
// Это приведёт к дубликатам. Правильный путь: хранить составной ключ вида collection:field:value,
|
||||
// и value — единственный. При Rebuild(partition) мы перезаписываем только те ключи, которые
|
||||
// встречаются в records. Для остальных value старые позиции этой partition останутся.
|
||||
// Значит нужен merge: для каждого value в records делаем Get, убираем старые Position с этой partition, добавляем новые.
|
||||
byFieldValue := make(map[string]map[string][]IndexPosition)
|
||||
for idx, rec := range records {
|
||||
recMap, ok := rec.(map[string]any)
|
||||
if !ok {
|
||||
@@ -145,21 +163,31 @@ func (s *MemcachedIndexStore) Rebuild(collection string, fields []string, record
|
||||
for _, field := range fields {
|
||||
val := getFieldValue(recMap, field)
|
||||
if byFieldValue[field] == nil {
|
||||
byFieldValue[field] = make(map[string][]int)
|
||||
byFieldValue[field] = make(map[string][]IndexPosition)
|
||||
}
|
||||
byFieldValue[field][val] = append(byFieldValue[field][val], idx)
|
||||
byFieldValue[field][val] = append(byFieldValue[field][val], IndexPosition{Partition: partition, LineIndex: idx})
|
||||
}
|
||||
}
|
||||
|
||||
for field, valMap := range byFieldValue {
|
||||
for val, list := range valMap {
|
||||
for val, newPositions := range valMap {
|
||||
key := s.memKey(collection, field, val)
|
||||
data, err := json.Marshal(list)
|
||||
if err != nil {
|
||||
continue
|
||||
var list []IndexPosition
|
||||
if data, err := s.client.Get(key); err == nil && len(data) > 0 {
|
||||
_ = json.Unmarshal(data, &list)
|
||||
}
|
||||
if err := s.client.Set(key, data, s.expireSec); err != nil {
|
||||
return fmt.Errorf("memcached set %s: %w", key, err)
|
||||
// Удаляем старые позиции этой партиции
|
||||
filtered := make([]IndexPosition, 0, len(list))
|
||||
for _, p := range list {
|
||||
if p.Partition != partition {
|
||||
filtered = append(filtered, p)
|
||||
}
|
||||
}
|
||||
list = append(filtered, newPositions...)
|
||||
if data, err := json.Marshal(list); err == nil {
|
||||
if err := s.client.Set(key, data, s.expireSec); err != nil {
|
||||
return fmt.Errorf("memcached set %s: %w", key, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ type LineDb struct {
|
||||
constructorOptions *LineDbOptions
|
||||
initOptions *LineDbInitOptions
|
||||
indexStore IndexStore
|
||||
reindexDone chan struct{} // закрывается при Close, останавливает горутину ReindexByTimer
|
||||
indexRebuildDone chan struct{} // закрывается при Close, останавливает горутину IndexRebuildTimer
|
||||
}
|
||||
|
||||
// NewLineDb создает новый экземпляр LineDb
|
||||
@@ -133,28 +133,42 @@ func (db *LineDb) Init(force bool, initOptions *LineDbInitOptions) error {
|
||||
}
|
||||
if db.indexStore != nil {
|
||||
for _, opt := range initOptions.Collections {
|
||||
if len(opt.IndexedFields) == 0 || db.isCollectionPartitioned(opt.CollectionName) {
|
||||
if len(opt.IndexedFields) == 0 {
|
||||
continue
|
||||
}
|
||||
adapter := db.adapters[opt.CollectionName]
|
||||
if adapter == nil {
|
||||
continue
|
||||
}
|
||||
records, err := adapter.Read(LineDbAdapterOptions{})
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to read collection %s for index rebuild: %w", opt.CollectionName, err)
|
||||
}
|
||||
if err := db.indexStore.Rebuild(opt.CollectionName, opt.IndexedFields, records); err != nil {
|
||||
return fmt.Errorf("failed to rebuild index for %s: %w", opt.CollectionName, err)
|
||||
if db.isCollectionPartitioned(opt.CollectionName) {
|
||||
// Партиции: обходим все существующие партиции (могут быть созданы ранее)
|
||||
baseName := opt.CollectionName
|
||||
for name, adapter := range db.adapters {
|
||||
if !strings.HasPrefix(name, baseName+"_") {
|
||||
continue
|
||||
}
|
||||
records, err := adapter.Read(LineDbAdapterOptions{})
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
_ = db.indexStore.Rebuild(opt.CollectionName, name, opt.IndexedFields, records)
|
||||
}
|
||||
} else {
|
||||
adapter := db.adapters[opt.CollectionName]
|
||||
if adapter != nil {
|
||||
records, err := adapter.Read(LineDbAdapterOptions{})
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to read collection %s for index rebuild: %w", opt.CollectionName, err)
|
||||
}
|
||||
if err := db.indexStore.Rebuild(opt.CollectionName, DefaultPartition, opt.IndexedFields, records); err != nil {
|
||||
return fmt.Errorf("failed to rebuild index for %s: %w", opt.CollectionName, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Периодический ребилд индексов
|
||||
if initOptions.ReindexByTimer > 0 && db.indexStore != nil {
|
||||
db.reindexDone = make(chan struct{})
|
||||
interval := time.Duration(initOptions.ReindexByTimer) * time.Millisecond
|
||||
go db.reindexByTimerLoop(interval)
|
||||
// Периодический ребилд индексов (отдельная горутина; при тике — полная блокировка db.mutex)
|
||||
if db.indexStore != nil && initOptions.IndexRebuildTimer > 0 {
|
||||
db.indexRebuildDone = make(chan struct{})
|
||||
interval := time.Duration(initOptions.IndexRebuildTimer) * time.Second
|
||||
go db.indexRebuildTimerLoop(interval)
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -274,6 +288,12 @@ func (db *LineDb) Insert(data any, collectionName string, options LineDbAdapterO
|
||||
|
||||
// Записываем данные с флагом транзакции
|
||||
writeOptions := LineDbAdapterOptions{InTransaction: true, InternalCall: true}
|
||||
if db.indexStore != nil {
|
||||
opts := db.getCollectionOptions(collectionName)
|
||||
if opts != nil && len(opts.IndexedFields) > 0 && db.isCollectionPartitioned(collectionName) {
|
||||
writeOptions.DoIndexing = true // индекс строится точечно при Write в партиции
|
||||
}
|
||||
}
|
||||
if err := db.Write(resultDataArray, collectionName, writeOptions); err != nil {
|
||||
return fmt.Errorf("failed to write data: %w", err)
|
||||
}
|
||||
@@ -285,7 +305,7 @@ func (db *LineDb) Insert(data any, collectionName string, options LineDbAdapterO
|
||||
}
|
||||
}
|
||||
|
||||
// Обновляем индекс (полная пересборка по коллекции)
|
||||
// Обновляем индекс (полная пересборка по коллекции) — только для непартиционированных
|
||||
if db.indexStore != nil {
|
||||
opts := db.getCollectionOptions(collectionName)
|
||||
if opts != nil && len(opts.IndexedFields) > 0 && !db.isCollectionPartitioned(collectionName) {
|
||||
@@ -293,7 +313,7 @@ func (db *LineDb) Insert(data any, collectionName string, options LineDbAdapterO
|
||||
if exists {
|
||||
allRecords, readErr := adapter.Read(LineDbAdapterOptions{})
|
||||
if readErr == nil {
|
||||
_ = db.indexStore.Rebuild(collectionName, opts.IndexedFields, allRecords)
|
||||
_ = db.indexStore.Rebuild(collectionName, DefaultPartition, opts.IndexedFields, allRecords)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -317,15 +337,27 @@ func (db *LineDb) Write(data any, collectionName string, options LineDbAdapterOp
|
||||
// Проверяем партиционирование
|
||||
if db.isCollectionPartitioned(collectionName) {
|
||||
dataArray := db.normalizeDataArray(data)
|
||||
opts := db.getCollectionOptions(collectionName)
|
||||
for _, item := range dataArray {
|
||||
adapter, err := db.getPartitionAdapter(item, collectionName)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to get partition adapter: %w", err)
|
||||
}
|
||||
|
||||
partitionName := adapter.GetCollectionName()
|
||||
var startLine int
|
||||
if options.DoIndexing && db.indexStore != nil && opts != nil && len(opts.IndexedFields) > 0 {
|
||||
if c, err := adapter.LineCount(); err == nil {
|
||||
startLine = c
|
||||
}
|
||||
}
|
||||
if err := adapter.Write(item, options); err != nil {
|
||||
return fmt.Errorf("failed to write to partition: %w", err)
|
||||
}
|
||||
if options.DoIndexing && db.indexStore != nil && opts != nil && len(opts.IndexedFields) > 0 {
|
||||
if m, err := db.toMap(item); err == nil {
|
||||
db.indexStore.IndexRecord(collectionName, partitionName, opts.IndexedFields, m, startLine)
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -354,7 +386,7 @@ func (db *LineDb) Write(data any, collectionName string, options LineDbAdapterOp
|
||||
dataArray := db.normalizeDataArray(data)
|
||||
for i, record := range dataArray {
|
||||
if m, err := db.toMap(record); err == nil {
|
||||
db.indexStore.IndexRecord(collectionName, opts.IndexedFields, m, startLine+i)
|
||||
db.indexStore.IndexRecord(collectionName, DefaultPartition, opts.IndexedFields, m, startLine+i)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -412,7 +444,7 @@ func (db *LineDb) Update(data any, collectionName string, filter any, options Li
|
||||
|
||||
// Пробуем точечный Update через индекс (без полного чтения файла)
|
||||
opts := db.getCollectionOptions(collectionName)
|
||||
if db.indexStore != nil && opts != nil && len(opts.IndexedFields) > 0 {
|
||||
if db.indexStore != nil && opts != nil && len(opts.IndexedFields) > 0 && !db.isCollectionPartitioned(collectionName) {
|
||||
result, used, err := db.tryIndexUpdate(adapter, filter, dataMap, collectionName, opts.IndexedFields, options)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -436,7 +468,7 @@ func (db *LineDb) Update(data any, collectionName string, filter any, options Li
|
||||
if opts != nil && len(opts.IndexedFields) > 0 {
|
||||
allRecords, readErr := adapter.Read(LineDbAdapterOptions{})
|
||||
if readErr == nil {
|
||||
_ = db.indexStore.Rebuild(collectionName, opts.IndexedFields, allRecords)
|
||||
_ = db.indexStore.Rebuild(collectionName, DefaultPartition, opts.IndexedFields, allRecords)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -502,7 +534,7 @@ func (db *LineDb) Delete(data any, collectionName string, options LineDbAdapterO
|
||||
if opts != nil && len(opts.IndexedFields) > 0 {
|
||||
allRecords, readErr := adapter.Read(LineDbAdapterOptions{})
|
||||
if readErr == nil {
|
||||
_ = db.indexStore.Rebuild(collectionName, opts.IndexedFields, allRecords)
|
||||
_ = db.indexStore.Rebuild(collectionName, DefaultPartition, opts.IndexedFields, allRecords)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -555,7 +587,29 @@ func (db *LineDb) ReadByFilter(filter any, collectionName string, options LineDb
|
||||
|
||||
// Проверяем партиционирование
|
||||
if db.isCollectionPartitioned(collectionName) {
|
||||
return db.readByFilterPartitioned(filter, collectionName, options)
|
||||
if db.indexStore != nil {
|
||||
hit, result, err := db.tryIndexLookupPartitioned(filter, collectionName, options)
|
||||
if err != nil || (options.FailOnFailureIndexRead && !hit) {
|
||||
return nil, fmt.Errorf("index read failed: %w", err)
|
||||
}
|
||||
if hit && err == nil {
|
||||
if db.cacheExternal != nil && !options.InTransaction {
|
||||
db.cacheExternal.Set(db.generateCacheKey(filter, collectionName), result)
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
}
|
||||
|
||||
// fallback to regular read
|
||||
result, err := db.readByFilterPartitioned(filter, collectionName, options)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// Обновляем кэш
|
||||
if db.cacheExternal != nil && !options.InTransaction {
|
||||
db.cacheExternal.Set(db.generateCacheKey(filter, collectionName), result)
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
adapter, exists := db.adapters[collectionName]
|
||||
@@ -565,7 +619,11 @@ func (db *LineDb) ReadByFilter(filter any, collectionName string, options LineDb
|
||||
|
||||
// Используем индекс, если фильтр — одно поле из IndexedFields
|
||||
if db.indexStore != nil {
|
||||
if hit, result, err := db.tryIndexLookup(adapter, filter, collectionName, options); hit && err == nil {
|
||||
hit, result, err := db.tryIndexLookup(adapter, filter, collectionName, DefaultPartition, options)
|
||||
if err != nil || (options.FailOnFailureIndexRead && !hit) {
|
||||
return nil, fmt.Errorf("index read failed: %w", err)
|
||||
}
|
||||
if hit && err == nil {
|
||||
if db.cacheExternal != nil && !options.InTransaction {
|
||||
db.cacheExternal.Set(db.generateCacheKey(filter, collectionName), result)
|
||||
}
|
||||
@@ -573,6 +631,7 @@ func (db *LineDb) ReadByFilter(filter any, collectionName string, options LineDb
|
||||
}
|
||||
}
|
||||
|
||||
// fallback to regular read
|
||||
result, err := adapter.ReadByFilter(filter, options)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -633,10 +692,10 @@ func (db *LineDb) Close() {
|
||||
db.mutex.Lock()
|
||||
defer db.mutex.Unlock()
|
||||
|
||||
// Останавливаем горутину ReindexByTimer
|
||||
if db.reindexDone != nil {
|
||||
close(db.reindexDone)
|
||||
db.reindexDone = nil
|
||||
// Останавливаем горутину периодического ребилда индексов (IndexRebuildTimer)
|
||||
if db.indexRebuildDone != nil {
|
||||
close(db.indexRebuildDone)
|
||||
db.indexRebuildDone = nil
|
||||
}
|
||||
|
||||
// Закрываем все адаптеры
|
||||
@@ -656,31 +715,44 @@ func (db *LineDb) Close() {
|
||||
db.partitionFunctions = make(map[string]func(any) string)
|
||||
}
|
||||
|
||||
// reindexByTimerLoop выполняет полный ребилд всех индексов с заданным интервалом.
|
||||
// Работает в отдельной горутине. Останавливается при закрытии db.reindexDone.
|
||||
func (db *LineDb) reindexByTimerLoop(interval time.Duration) {
|
||||
// indexRebuildTimerLoop выполняет полный ребилд всех индексов с заданным интервалом (IndexRebuildTimer).
|
||||
// Работает в отдельной горутине; при каждом тике берёт db.mutex.Lock() на время ребилда.
|
||||
// Останавливается при закрытии db.indexRebuildDone.
|
||||
func (db *LineDb) indexRebuildTimerLoop(interval time.Duration) {
|
||||
ticker := time.NewTicker(interval)
|
||||
defer ticker.Stop()
|
||||
for {
|
||||
select {
|
||||
case <-db.reindexDone:
|
||||
case <-db.indexRebuildDone:
|
||||
return
|
||||
case <-ticker.C:
|
||||
db.mutex.Lock()
|
||||
if db.indexStore != nil && db.initOptions != nil {
|
||||
for _, opt := range db.initOptions.Collections {
|
||||
if len(opt.IndexedFields) == 0 || db.isCollectionPartitioned(opt.CollectionName) {
|
||||
if len(opt.IndexedFields) == 0 {
|
||||
continue
|
||||
}
|
||||
adapter := db.adapters[opt.CollectionName]
|
||||
if adapter == nil {
|
||||
continue
|
||||
if db.isCollectionPartitioned(opt.CollectionName) {
|
||||
baseName := opt.CollectionName
|
||||
for name, adapter := range db.adapters {
|
||||
if !strings.HasPrefix(name, baseName+"_") {
|
||||
continue
|
||||
}
|
||||
records, err := adapter.Read(LineDbAdapterOptions{})
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
_ = db.indexStore.Rebuild(opt.CollectionName, name, opt.IndexedFields, records)
|
||||
}
|
||||
} else {
|
||||
adapter := db.adapters[opt.CollectionName]
|
||||
if adapter != nil {
|
||||
records, err := adapter.Read(LineDbAdapterOptions{})
|
||||
if err == nil {
|
||||
_ = db.indexStore.Rebuild(opt.CollectionName, DefaultPartition, opt.IndexedFields, records)
|
||||
}
|
||||
}
|
||||
}
|
||||
records, err := adapter.Read(LineDbAdapterOptions{})
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
_ = db.indexStore.Rebuild(opt.CollectionName, opt.IndexedFields, records)
|
||||
}
|
||||
}
|
||||
db.mutex.Unlock()
|
||||
@@ -704,20 +776,16 @@ func (db *LineDb) getBaseCollectionName(collectionName string) string {
|
||||
return collectionName
|
||||
}
|
||||
|
||||
// tryIndexLookup пытается выполнить поиск через индекс.
|
||||
// Если фильтр — map с несколькими полями, выбирается первое поле из IndexedFields,
|
||||
// по нему читаются строки через индекс, затем в памяти накладывается полный фильтр.
|
||||
// Возвращает (true, result) если индекс использован, (false, nil) иначе.
|
||||
func (db *LineDb) tryIndexLookup(adapter *JSONLFile, filter any, collectionName string, options LineDbAdapterOptions) (bool, []any, error) {
|
||||
// tryIndexLookup пытается выполнить поиск через индекс (для одной партиции/коллекции).
|
||||
func (db *LineDb) tryIndexLookup(adapter *JSONLFile, filter any, collectionName, partition string, options LineDbAdapterOptions) (bool, []any, error) {
|
||||
filterMap, ok := filter.(map[string]any)
|
||||
if !ok || len(filterMap) == 0 {
|
||||
return false, nil, nil
|
||||
}
|
||||
opts := adapter.GetOptions()
|
||||
if len(opts.IndexedFields) == 0 {
|
||||
opts := db.getCollectionOptions(collectionName)
|
||||
if opts == nil || len(opts.IndexedFields) == 0 {
|
||||
return false, nil, nil
|
||||
}
|
||||
// Находим первое индексируемое поле, которое есть в фильтре
|
||||
var field string
|
||||
var value any
|
||||
for _, idxField := range opts.IndexedFields {
|
||||
@@ -731,11 +799,21 @@ func (db *LineDb) tryIndexLookup(adapter *JSONLFile, filter any, collectionName
|
||||
return false, nil, nil
|
||||
}
|
||||
valStr := valueToIndexKey(value)
|
||||
indexes, err := db.indexStore.Lookup(collectionName, field, valStr)
|
||||
if err != nil || indexes == nil || len(indexes) == 0 {
|
||||
positions, err := db.indexStore.Lookup(collectionName, field, valStr)
|
||||
if err != nil || len(positions) == 0 {
|
||||
return false, nil, err
|
||||
}
|
||||
records, err := adapter.ReadByLineIndexes(indexes, options)
|
||||
// Фильтруем только позиции нужной партиции
|
||||
var lineIndexes []int
|
||||
for _, p := range positions {
|
||||
if p.Partition == partition {
|
||||
lineIndexes = append(lineIndexes, p.LineIndex)
|
||||
}
|
||||
}
|
||||
if len(lineIndexes) == 0 {
|
||||
return false, nil, nil
|
||||
}
|
||||
records, err := adapter.ReadByLineIndexes(lineIndexes, options)
|
||||
if err != nil {
|
||||
return false, nil, err
|
||||
}
|
||||
@@ -753,6 +831,65 @@ func (db *LineDb) tryIndexLookup(adapter *JSONLFile, filter any, collectionName
|
||||
return true, filtered, nil
|
||||
}
|
||||
|
||||
// tryIndexLookupPartitioned — поиск через индекс для партиционированной коллекции.
|
||||
func (db *LineDb) tryIndexLookupPartitioned(filter any, collectionName string, options LineDbAdapterOptions) (bool, []any, error) {
|
||||
opts := db.getCollectionOptions(collectionName)
|
||||
if opts == nil || len(opts.IndexedFields) == 0 {
|
||||
return false, nil, nil
|
||||
}
|
||||
filterMap, ok := filter.(map[string]any)
|
||||
if !ok || len(filterMap) == 0 {
|
||||
return false, nil, nil
|
||||
}
|
||||
var field string
|
||||
var value any
|
||||
for _, idxField := range opts.IndexedFields {
|
||||
if v, exists := filterMap[idxField]; exists {
|
||||
field = idxField
|
||||
value = v
|
||||
break
|
||||
}
|
||||
}
|
||||
if field == "" {
|
||||
return false, nil, nil
|
||||
}
|
||||
valStr := valueToIndexKey(value)
|
||||
positions, err := db.indexStore.Lookup(collectionName, field, valStr)
|
||||
if err != nil || len(positions) == 0 {
|
||||
return false, nil, err
|
||||
}
|
||||
// Группируем по партиции
|
||||
byPartition := make(map[string][]int)
|
||||
for _, p := range positions {
|
||||
byPartition[p.Partition] = append(byPartition[p.Partition], p.LineIndex)
|
||||
}
|
||||
var allRecords []any
|
||||
for partitionName, lineIndexes := range byPartition {
|
||||
adapter := db.adapters[partitionName]
|
||||
if adapter == nil {
|
||||
continue
|
||||
}
|
||||
recs, err := adapter.ReadByLineIndexes(lineIndexes, options)
|
||||
if err != nil {
|
||||
return false, nil, err
|
||||
}
|
||||
allRecords = append(allRecords, recs...)
|
||||
}
|
||||
if len(allRecords) == 0 {
|
||||
return false, nil, nil
|
||||
}
|
||||
if len(filterMap) == 1 {
|
||||
return true, allRecords, nil
|
||||
}
|
||||
var filtered []any
|
||||
for _, rec := range allRecords {
|
||||
if db.matchesFilter(rec, filter, options.StrictCompare) {
|
||||
filtered = append(filtered, rec)
|
||||
}
|
||||
}
|
||||
return true, filtered, nil
|
||||
}
|
||||
|
||||
// tryIndexUpdate выполняет точечное обновление через индекс. Возвращает (result, used, err).
|
||||
func (db *LineDb) tryIndexUpdate(adapter *JSONLFile, filter any, dataMap map[string]any, collectionName string, indexedFields []string, options LineDbAdapterOptions) ([]any, bool, error) {
|
||||
filterMap, ok := filter.(map[string]any)
|
||||
@@ -772,10 +909,19 @@ func (db *LineDb) tryIndexUpdate(adapter *JSONLFile, filter any, dataMap map[str
|
||||
return nil, false, nil
|
||||
}
|
||||
valStr := valueToIndexKey(value)
|
||||
indexes, err := db.indexStore.Lookup(collectionName, field, valStr)
|
||||
if err != nil || indexes == nil || len(indexes) == 0 {
|
||||
posList, err := db.indexStore.Lookup(collectionName, field, valStr)
|
||||
if err != nil || len(posList) == 0 {
|
||||
return nil, false, err
|
||||
}
|
||||
var indexes []int
|
||||
for _, p := range posList {
|
||||
if p.Partition == DefaultPartition {
|
||||
indexes = append(indexes, p.LineIndex)
|
||||
}
|
||||
}
|
||||
if len(indexes) == 0 {
|
||||
return nil, false, nil
|
||||
}
|
||||
opt := options
|
||||
opt.InTransaction = true
|
||||
records, positions, err := adapter.ReadByLineIndexesWithPositions(indexes, opt)
|
||||
@@ -814,12 +960,12 @@ func (db *LineDb) tryIndexUpdate(adapter *JSONLFile, filter any, dataMap map[str
|
||||
}
|
||||
for i, rec := range toUpdate {
|
||||
if m, ok := rec.(map[string]any); ok {
|
||||
db.indexStore.UnindexRecord(collectionName, indexedFields, m, toUpdatePos[i])
|
||||
db.indexStore.UnindexRecord(collectionName, DefaultPartition, indexedFields, m, toUpdatePos[i])
|
||||
}
|
||||
}
|
||||
for i, rec := range updated {
|
||||
if m, ok := rec.(map[string]any); ok {
|
||||
db.indexStore.IndexRecord(collectionName, indexedFields, m, toUpdatePos[i])
|
||||
db.indexStore.IndexRecord(collectionName, DefaultPartition, indexedFields, m, toUpdatePos[i])
|
||||
}
|
||||
}
|
||||
return updated, true, nil
|
||||
@@ -844,10 +990,19 @@ func (db *LineDb) tryIndexDelete(adapter *JSONLFile, filter any, collectionName
|
||||
return nil, false, nil
|
||||
}
|
||||
valStr := valueToIndexKey(value)
|
||||
indexes, err := db.indexStore.Lookup(collectionName, field, valStr)
|
||||
if err != nil || indexes == nil || len(indexes) == 0 {
|
||||
posList, err := db.indexStore.Lookup(collectionName, field, valStr)
|
||||
if err != nil || len(posList) == 0 {
|
||||
return nil, false, err
|
||||
}
|
||||
var indexes []int
|
||||
for _, p := range posList {
|
||||
if p.Partition == DefaultPartition {
|
||||
indexes = append(indexes, p.LineIndex)
|
||||
}
|
||||
}
|
||||
if len(indexes) == 0 {
|
||||
return nil, false, nil
|
||||
}
|
||||
opt := options
|
||||
opt.InTransaction = true
|
||||
records, positions, err := adapter.ReadByLineIndexesWithPositions(indexes, opt)
|
||||
@@ -871,7 +1026,7 @@ func (db *LineDb) tryIndexDelete(adapter *JSONLFile, filter any, collectionName
|
||||
}
|
||||
for i, rec := range toDel {
|
||||
if m, ok := rec.(map[string]any); ok {
|
||||
db.indexStore.UnindexRecord(collectionName, indexedFields, m, toDelPos[i])
|
||||
db.indexStore.UnindexRecord(collectionName, DefaultPartition, indexedFields, m, toDelPos[i])
|
||||
}
|
||||
}
|
||||
return toDel, true, nil
|
||||
@@ -1321,19 +1476,20 @@ func (db *LineDb) normalizeFilter(filter any) (any, error) {
|
||||
}
|
||||
|
||||
func (db *LineDb) updatePartitioned(data any, collectionName string, filter any, options LineDbAdapterOptions) ([]any, error) {
|
||||
// Получаем все партиции
|
||||
partitionFiles, err := db.getPartitionFiles(collectionName)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
opts := db.getCollectionOptions(collectionName)
|
||||
|
||||
var allResults []any
|
||||
for _, filename := range partitionFiles {
|
||||
// Находим адаптер по имени файла
|
||||
var adapter *JSONLFile
|
||||
var partitionName string
|
||||
for name, adapterFile := range db.collections {
|
||||
if adapterFile == filename {
|
||||
adapter = db.adapters[name]
|
||||
partitionName = name
|
||||
break
|
||||
}
|
||||
}
|
||||
@@ -1344,6 +1500,12 @@ func (db *LineDb) updatePartitioned(data any, collectionName string, filter any,
|
||||
return nil, err
|
||||
}
|
||||
allResults = append(allResults, results...)
|
||||
if db.indexStore != nil && opts != nil && len(opts.IndexedFields) > 0 {
|
||||
records, readErr := adapter.Read(LineDbAdapterOptions{InTransaction: true})
|
||||
if readErr == nil {
|
||||
_ = db.indexStore.Rebuild(collectionName, partitionName, opts.IndexedFields, records)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1351,19 +1513,20 @@ func (db *LineDb) updatePartitioned(data any, collectionName string, filter any,
|
||||
}
|
||||
|
||||
func (db *LineDb) deletePartitioned(data any, collectionName string, options LineDbAdapterOptions) ([]any, error) {
|
||||
// Получаем все партиции
|
||||
partitionFiles, err := db.getPartitionFiles(collectionName)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
opts := db.getCollectionOptions(collectionName)
|
||||
|
||||
var allResults []any
|
||||
for _, filename := range partitionFiles {
|
||||
// Находим адаптер по имени файла
|
||||
var adapter *JSONLFile
|
||||
var partitionName string
|
||||
for name, adapterFile := range db.collections {
|
||||
if adapterFile == filename {
|
||||
adapter = db.adapters[name]
|
||||
partitionName = name
|
||||
break
|
||||
}
|
||||
}
|
||||
@@ -1374,6 +1537,12 @@ func (db *LineDb) deletePartitioned(data any, collectionName string, options Lin
|
||||
return nil, err
|
||||
}
|
||||
allResults = append(allResults, results...)
|
||||
if db.indexStore != nil && opts != nil && len(opts.IndexedFields) > 0 {
|
||||
records, readErr := adapter.Read(LineDbAdapterOptions{InTransaction: true})
|
||||
if readErr == nil {
|
||||
_ = db.indexStore.Rebuild(collectionName, partitionName, opts.IndexedFields, records)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1672,7 +1841,7 @@ func (db *LineDb) GetCacheForTest(accessKey string) map[string]any {
|
||||
}
|
||||
|
||||
// GetIndexSnapshotForTest возвращает снимок индекса для тестов (только InMemoryIndexStore).
|
||||
// Доступ только при accessKey == "give_me_cache". Ключ — "collection:field", значение — map[value][]int (номера строк).
|
||||
// Доступ только при accessKey == "give_me_cache". Ключ — "collection:field", значение — map[value][]IndexPosition.
|
||||
func (db *LineDb) GetIndexSnapshotForTest(accessKey string) map[string]any {
|
||||
const testAccessKey = "give_me_cache"
|
||||
if accessKey != testAccessKey || db.indexStore == nil {
|
||||
|
||||
@@ -52,8 +52,9 @@ type LineDbInitOptions struct {
|
||||
CacheTTL time.Duration `json:"cacheTTL,omitempty"`
|
||||
Collections []JSONLFileOptions `json:"collections"`
|
||||
DBFolder string `json:"dbFolder,omitempty"`
|
||||
Partitions []PartitionCollection `json:"partitions,omitempty"`
|
||||
ReindexByTimer int `json:"reindexByTimer,omitempty"` // интервал в ms; если > 0 — периодический полный ребилд всех индексов с блокировкой
|
||||
Partitions []PartitionCollection `json:"partitions,omitempty"`
|
||||
// IndexRebuildTimer — интервал в секундах; если > 0 — в отдельной горутине периодический полный ребилд всех индексов с блокировкой базы (db.mutex).
|
||||
IndexRebuildTimer int `json:"indexRebuildTimer,omitempty"`
|
||||
}
|
||||
|
||||
// EmptyValueMode определяет, что считать "пустым" при проверке required/unique
|
||||
@@ -180,6 +181,9 @@ type LineDbAdapterOptions struct {
|
||||
OptimisticRead bool `json:"optimisticRead,omitempty"`
|
||||
ReturnChain bool `json:"returnChain,omitempty"`
|
||||
DoIndexing bool `json:"doIndexing,omitempty"` // при true — после Write делать точечное индексирование новых записей
|
||||
// FailOnFailureIndexRead — при true: если ReadByFilter пошёл по индексу и получил ошибку (Lookup / ReadByLineIndexes),
|
||||
// вернуть её и не делать полный перебор по коллекции.
|
||||
FailOnFailureIndexRead bool `json:"failOnFailureIndexRead,omitempty"`
|
||||
}
|
||||
|
||||
// TransactionOptions представляет опции транзакции
|
||||
|
||||
Reference in New Issue
Block a user