Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| fafe0d4a66 | |||
| a1bbd9177a |
@@ -6,7 +6,7 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"direct-dev.ru/gitea/GiteaAdmin/elowdb-go"
|
||||
"direct-dev.ru/gitea/GiteaAdmin/elowdb-go/pkg/linedb"
|
||||
)
|
||||
|
||||
func TestCustomJSONSerialization(t *testing.T) {
|
||||
|
||||
@@ -5,7 +5,7 @@ import (
|
||||
"log"
|
||||
"time"
|
||||
|
||||
"direct-dev.ru/gitea/GiteaAdmin/elowdb-go"
|
||||
"direct-dev.ru/gitea/GiteaAdmin/elowdb-go/pkg/linedb"
|
||||
)
|
||||
|
||||
// testDeleteOneRecordByID тестирует удаление одной записи по ID
|
||||
|
||||
@@ -7,7 +7,7 @@ import (
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"direct-dev.ru/gitea/GiteaAdmin/elowdb-go"
|
||||
"direct-dev.ru/gitea/GiteaAdmin/elowdb-go/pkg/linedb"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
||||
@@ -20,7 +20,7 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"direct-dev.ru/gitea/GiteaAdmin/elowdb-go"
|
||||
"direct-dev.ru/gitea/GiteaAdmin/elowdb-go/pkg/linedb"
|
||||
)
|
||||
|
||||
const (
|
||||
|
||||
@@ -10,7 +10,7 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"direct-dev.ru/gitea/GiteaAdmin/elowdb-go"
|
||||
"direct-dev.ru/gitea/GiteaAdmin/elowdb-go/pkg/linedb"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
||||
@@ -33,8 +33,9 @@ type IndexStore interface {
|
||||
UnindexRecord(collection, partition string, fields []string, record map[string]any, lineIndex int)
|
||||
|
||||
// Rebuild перестраивает вклад в индекс для одной партиции (или всей коллекции, если одна партиция).
|
||||
// partition — имя партиции; records — записи, позиция в срезе = lineIndex.
|
||||
Rebuild(collection, partition string, fields []string, records []any) error
|
||||
// lineIndexes[i] — 0-based номер физической строки в файле для records[i] (после пустых/удалённых строк).
|
||||
// Если lineIndexes == nil или len != len(records), используются плотные индексы 0..len-1 (устаревшее поведение).
|
||||
Rebuild(collection, partition string, fields []string, records []any, lineIndexes []int) error
|
||||
|
||||
// Clear очищает индекс коллекции (все партиции).
|
||||
Clear(collection string) error
|
||||
@@ -164,7 +165,7 @@ func (s *InMemoryIndexStore) Lookup(collection, field, value string) ([]IndexPos
|
||||
}
|
||||
|
||||
// Rebuild перестраивает вклад партиции в индекс.
|
||||
func (s *InMemoryIndexStore) Rebuild(collection, partition string, fields []string, records []any) error {
|
||||
func (s *InMemoryIndexStore) Rebuild(collection, partition string, fields []string, records []any, lineIndexes []int) error {
|
||||
if partition == "" {
|
||||
partition = DefaultPartition
|
||||
}
|
||||
@@ -194,7 +195,11 @@ func (s *InMemoryIndexStore) Rebuild(collection, partition string, fields []stri
|
||||
}
|
||||
|
||||
// Добавляем новые позиции
|
||||
for idx, rec := range records {
|
||||
for i, rec := range records {
|
||||
lineIdx := i
|
||||
if lineIndexes != nil && i < len(lineIndexes) {
|
||||
lineIdx = lineIndexes[i]
|
||||
}
|
||||
recMap, ok := rec.(map[string]any)
|
||||
if !ok {
|
||||
continue
|
||||
@@ -205,7 +210,7 @@ func (s *InMemoryIndexStore) Rebuild(collection, partition string, fields []stri
|
||||
if s.index[key] == nil {
|
||||
s.index[key] = make(map[string][]IndexPosition)
|
||||
}
|
||||
s.index[key][val] = append(s.index[key][val], IndexPosition{Partition: partition, LineIndex: idx})
|
||||
s.index[key][val] = append(s.index[key][val], IndexPosition{Partition: partition, LineIndex: lineIdx})
|
||||
}
|
||||
}
|
||||
return nil
|
||||
|
||||
@@ -133,7 +133,7 @@ func (s *MemcachedIndexStore) Lookup(collection, field, value string) ([]IndexPo
|
||||
}
|
||||
|
||||
// Rebuild перестраивает вклад партиции в индекс.
|
||||
func (s *MemcachedIndexStore) Rebuild(collection, partition string, fields []string, records []any) error {
|
||||
func (s *MemcachedIndexStore) Rebuild(collection, partition string, fields []string, records []any, lineIndexes []int) error {
|
||||
if partition == "" {
|
||||
partition = DefaultPartition
|
||||
}
|
||||
@@ -155,7 +155,11 @@ func (s *MemcachedIndexStore) Rebuild(collection, partition string, fields []str
|
||||
// встречаются в records. Для остальных value старые позиции этой partition останутся.
|
||||
// Значит нужен merge: для каждого value в records делаем Get, убираем старые Position с этой partition, добавляем новые.
|
||||
byFieldValue := make(map[string]map[string][]IndexPosition)
|
||||
for idx, rec := range records {
|
||||
for i, rec := range records {
|
||||
lineIdx := i
|
||||
if lineIndexes != nil && i < len(lineIndexes) {
|
||||
lineIdx = lineIndexes[i]
|
||||
}
|
||||
recMap, ok := rec.(map[string]any)
|
||||
if !ok {
|
||||
continue
|
||||
@@ -165,7 +169,7 @@ func (s *MemcachedIndexStore) Rebuild(collection, partition string, fields []str
|
||||
if byFieldValue[field] == nil {
|
||||
byFieldValue[field] = make(map[string][]IndexPosition)
|
||||
}
|
||||
byFieldValue[field][val] = append(byFieldValue[field][val], IndexPosition{Partition: partition, LineIndex: idx})
|
||||
byFieldValue[field][val] = append(byFieldValue[field][val], IndexPosition{Partition: partition, LineIndex: lineIdx})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -402,6 +402,83 @@ func (j *JSONLFile) Read(options LineDbAdapterOptions) ([]any, error) {
|
||||
return records, scanner.Err()
|
||||
}
|
||||
|
||||
// ReadWithPhysicalLineIndexes как Read, но для каждой записи возвращает 0-based индекс строки (слота),
|
||||
// в том же смысле, что ReadByLineIndexes/WriteAtLineIndexes: смещение в файле = lineIndex * allocSize.
|
||||
// Пустые слоты (пробелы после удаления и т.п.) пропускаются; индекс — номер слота, а не порядковый номер записи.
|
||||
func (j *JSONLFile) ReadWithPhysicalLineIndexes(options LineDbAdapterOptions) ([]any, []int, error) {
|
||||
if !options.InTransaction {
|
||||
j.mutex.RLock()
|
||||
defer j.mutex.RUnlock()
|
||||
}
|
||||
|
||||
if !j.initialized {
|
||||
return nil, nil, fmt.Errorf("file not initialized")
|
||||
}
|
||||
if j.allocSize <= 0 {
|
||||
return nil, nil, fmt.Errorf("invalid allocSize")
|
||||
}
|
||||
|
||||
file, err := os.Open(j.filename)
|
||||
if err != nil {
|
||||
return nil, nil, fmt.Errorf("failed to open file: %w", err)
|
||||
}
|
||||
defer file.Close()
|
||||
|
||||
info, err := file.Stat()
|
||||
if err != nil {
|
||||
return nil, nil, fmt.Errorf("stat file: %w", err)
|
||||
}
|
||||
nSlots := int(info.Size()) / j.allocSize
|
||||
|
||||
buf := make([]byte, j.allocSize)
|
||||
var records []any
|
||||
var lineIndexes []int
|
||||
|
||||
for slot := 0; slot < nSlots; slot++ {
|
||||
n, err := io.ReadFull(file, buf)
|
||||
if err == io.EOF || err == io.ErrUnexpectedEOF {
|
||||
break
|
||||
}
|
||||
if err != nil {
|
||||
return nil, nil, fmt.Errorf("read slot %d: %w", slot, err)
|
||||
}
|
||||
if n != j.allocSize {
|
||||
break
|
||||
}
|
||||
|
||||
line := string(buf[:n])
|
||||
line = strings.TrimRight(line, "\n")
|
||||
line = strings.TrimRight(line, " ")
|
||||
if strings.TrimSpace(line) == "" {
|
||||
continue
|
||||
}
|
||||
|
||||
if j.cypherKey != "" && !j.options.Encode {
|
||||
decoded, err := base64.StdEncoding.DecodeString(line)
|
||||
if err != nil {
|
||||
if j.options.SkipInvalidLines {
|
||||
continue
|
||||
}
|
||||
return nil, nil, fmt.Errorf("failed to decode base64: %w", err)
|
||||
}
|
||||
line = string(decoded)
|
||||
}
|
||||
|
||||
var record any
|
||||
if err := j.jsonUnmarshal([]byte(line), &record); err != nil {
|
||||
if j.options.SkipInvalidLines {
|
||||
continue
|
||||
}
|
||||
return nil, nil, fmt.Errorf("failed to unmarshal JSON: %w", err)
|
||||
}
|
||||
|
||||
records = append(records, record)
|
||||
lineIndexes = append(lineIndexes, slot)
|
||||
}
|
||||
|
||||
return records, lineIndexes, nil
|
||||
}
|
||||
|
||||
// ReadByLineIndexes читает записи по номерам строк (0-based) с использованием random access.
|
||||
// Ожидается, что файл нормализован и каждая строка имеет длину allocSize байт (включая \n),
|
||||
// как это обеспечивает Init/normalizeExistingFile/rewriteFile.
|
||||
|
||||
@@ -4,7 +4,9 @@ import (
|
||||
"sync"
|
||||
)
|
||||
|
||||
// LastIDManager управляет последними ID для коллекций
|
||||
// LastIDManager управляет последними ID для коллекций.
|
||||
// Ключ — полное имя коллекции (как в NextID/Insert), без обрезки по «_»:
|
||||
// иначе user_data и events_A ломались бы на первый сегмент.
|
||||
type LastIDManager struct {
|
||||
lastIDs map[string]int
|
||||
mutex sync.RWMutex
|
||||
@@ -23,53 +25,32 @@ func GetLastIDManagerInstance() *LastIDManager {
|
||||
return lastIDManagerInstance
|
||||
}
|
||||
|
||||
// GetLastID получает последний ID для коллекции
|
||||
func (l *LastIDManager) GetLastID(filename string) int {
|
||||
// GetLastID получает последний ID для коллекции (ключ — полное имя коллекции).
|
||||
func (l *LastIDManager) GetLastID(collectionKey string) int {
|
||||
l.mutex.RLock()
|
||||
defer l.mutex.RUnlock()
|
||||
|
||||
baseFileName := l.getBaseFileName(filename)
|
||||
return l.lastIDs[baseFileName]
|
||||
return l.lastIDs[collectionKey]
|
||||
}
|
||||
|
||||
// SetLastID устанавливает последний ID для коллекции
|
||||
func (l *LastIDManager) SetLastID(filename string, id int) {
|
||||
// SetLastID устанавливает последний ID для коллекции, если id больше текущего.
|
||||
func (l *LastIDManager) SetLastID(collectionKey string, id int) {
|
||||
l.mutex.Lock()
|
||||
defer l.mutex.Unlock()
|
||||
|
||||
baseFileName := l.getBaseFileName(filename)
|
||||
currentID := l.lastIDs[baseFileName]
|
||||
currentID := l.lastIDs[collectionKey]
|
||||
if currentID < id {
|
||||
l.lastIDs[baseFileName] = id
|
||||
l.lastIDs[collectionKey] = id
|
||||
}
|
||||
}
|
||||
|
||||
// IncrementLastID увеличивает последний ID для коллекции
|
||||
func (l *LastIDManager) IncrementLastID(filename string) int {
|
||||
func (l *LastIDManager) IncrementLastID(collectionKey string) int {
|
||||
l.mutex.Lock()
|
||||
defer l.mutex.Unlock()
|
||||
|
||||
baseFileName := l.getBaseFileName(filename)
|
||||
currentID := l.lastIDs[baseFileName]
|
||||
currentID := l.lastIDs[collectionKey]
|
||||
newID := currentID + 1
|
||||
l.lastIDs[baseFileName] = newID
|
||||
l.lastIDs[collectionKey] = newID
|
||||
return newID
|
||||
}
|
||||
|
||||
// getBaseFileName извлекает базовое имя файла
|
||||
func (l *LastIDManager) getBaseFileName(filename string) string {
|
||||
if idx := l.findPartitionSeparator(filename); idx != -1 {
|
||||
return filename[:idx]
|
||||
}
|
||||
return filename
|
||||
}
|
||||
|
||||
// findPartitionSeparator находит разделитель партиции
|
||||
func (l *LastIDManager) findPartitionSeparator(filename string) int {
|
||||
for i, char := range filename {
|
||||
if char == '_' {
|
||||
return i
|
||||
}
|
||||
}
|
||||
return -1
|
||||
}
|
||||
|
||||
@@ -143,20 +143,20 @@ func (db *LineDb) Init(force bool, initOptions *LineDbInitOptions) error {
|
||||
if !strings.HasPrefix(name, baseName+"_") {
|
||||
continue
|
||||
}
|
||||
records, err := adapter.Read(LineDbAdapterOptions{})
|
||||
records, lineIdx, err := adapter.ReadWithPhysicalLineIndexes(LineDbAdapterOptions{})
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
_ = db.indexStore.Rebuild(opt.CollectionName, name, opt.IndexedFields, records)
|
||||
_ = db.indexStore.Rebuild(opt.CollectionName, name, opt.IndexedFields, records, lineIdx)
|
||||
}
|
||||
} else {
|
||||
adapter := db.adapters[opt.CollectionName]
|
||||
if adapter != nil {
|
||||
records, err := adapter.Read(LineDbAdapterOptions{})
|
||||
records, lineIdx, err := adapter.ReadWithPhysicalLineIndexes(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 {
|
||||
if err := db.indexStore.Rebuild(opt.CollectionName, DefaultPartition, opt.IndexedFields, records, lineIdx); err != nil {
|
||||
return fmt.Errorf("failed to rebuild index for %s: %w", opt.CollectionName, err)
|
||||
}
|
||||
}
|
||||
@@ -171,6 +171,81 @@ func (db *LineDb) Init(force bool, initOptions *LineDbInitOptions) error {
|
||||
go db.indexRebuildTimerLoop(interval)
|
||||
}
|
||||
|
||||
if err := db.seedLastIDsFromData(dbFolder); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// seedLastIDsFromData выставляет LastIDManager по максимальному id в существующих данных
|
||||
// (после рестарта процесса счётчик не начинается с 1).
|
||||
func (db *LineDb) seedLastIDsFromData(dbFolder string) error {
|
||||
for i, opt := range db.initOptions.Collections {
|
||||
collectionName := opt.CollectionName
|
||||
if collectionName == "" {
|
||||
collectionName = fmt.Sprintf("collection_%d", i+1)
|
||||
}
|
||||
if db.isCollectionPartitioned(collectionName) {
|
||||
if err := db.seedLastIDPartitioned(dbFolder, collectionName); err != nil {
|
||||
return err
|
||||
}
|
||||
continue
|
||||
}
|
||||
adapter := db.adapters[collectionName]
|
||||
if adapter == nil {
|
||||
continue
|
||||
}
|
||||
records, err := adapter.Read(LineDbAdapterOptions{})
|
||||
if err != nil {
|
||||
return fmt.Errorf("seed last id: read %s: %w", collectionName, err)
|
||||
}
|
||||
db.lastIDManager.SetLastID(collectionName, db.GetMaxID(records))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// seedLastIDPartitioned — максимальный id по базовому файлу и всем events_*.jsonl на диске.
|
||||
// NextID для партиций вызывается с логическим именем (например events), ключ тот же.
|
||||
func (db *LineDb) seedLastIDPartitioned(dbFolder, baseName string) error {
|
||||
maxID := 0
|
||||
if a := db.adapters[baseName]; a != nil {
|
||||
recs, err := a.Read(LineDbAdapterOptions{})
|
||||
if err != nil {
|
||||
return fmt.Errorf("seed last id: read base %s: %w", baseName, err)
|
||||
}
|
||||
if m := db.GetMaxID(recs); m > maxID {
|
||||
maxID = m
|
||||
}
|
||||
}
|
||||
pattern := filepath.Join(dbFolder, baseName+"_*.jsonl")
|
||||
matches, err := filepath.Glob(pattern)
|
||||
if err != nil {
|
||||
return fmt.Errorf("seed last id: glob %s: %w", pattern, err)
|
||||
}
|
||||
for _, path := range matches {
|
||||
base := filepath.Base(path)
|
||||
partName := strings.TrimSuffix(base, ".jsonl")
|
||||
var adapter *JSONLFile
|
||||
if existing, ok := db.adapters[partName]; ok {
|
||||
adapter = existing
|
||||
} else {
|
||||
adapter = NewJSONLFile(path, "", JSONLFileOptions{CollectionName: partName})
|
||||
if err := adapter.Init(false, LineDbAdapterOptions{}); err != nil {
|
||||
continue
|
||||
}
|
||||
db.adapters[partName] = adapter
|
||||
db.collections[partName] = path
|
||||
}
|
||||
recs, err := adapter.Read(LineDbAdapterOptions{})
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
if m := db.GetMaxID(recs); m > maxID {
|
||||
maxID = m
|
||||
}
|
||||
}
|
||||
db.lastIDManager.SetLastID(baseName, maxID)
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -311,9 +386,9 @@ func (db *LineDb) Insert(data any, collectionName string, options LineDbAdapterO
|
||||
if opts != nil && len(opts.IndexedFields) > 0 && !db.isCollectionPartitioned(collectionName) {
|
||||
adapter, exists := db.adapters[collectionName]
|
||||
if exists {
|
||||
allRecords, readErr := adapter.Read(LineDbAdapterOptions{})
|
||||
allRecords, lineIdx, readErr := adapter.ReadWithPhysicalLineIndexes(LineDbAdapterOptions{})
|
||||
if readErr == nil {
|
||||
_ = db.indexStore.Rebuild(collectionName, DefaultPartition, opts.IndexedFields, allRecords)
|
||||
_ = db.indexStore.Rebuild(collectionName, DefaultPartition, opts.IndexedFields, allRecords, lineIdx)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -466,9 +541,9 @@ func (db *LineDb) Update(data any, collectionName string, filter any, options Li
|
||||
if db.indexStore != nil {
|
||||
opts := db.getCollectionOptions(collectionName)
|
||||
if opts != nil && len(opts.IndexedFields) > 0 {
|
||||
allRecords, readErr := adapter.Read(LineDbAdapterOptions{})
|
||||
allRecords, lineIdx, readErr := adapter.ReadWithPhysicalLineIndexes(LineDbAdapterOptions{})
|
||||
if readErr == nil {
|
||||
_ = db.indexStore.Rebuild(collectionName, DefaultPartition, opts.IndexedFields, allRecords)
|
||||
_ = db.indexStore.Rebuild(collectionName, DefaultPartition, opts.IndexedFields, allRecords, lineIdx)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -532,9 +607,9 @@ func (db *LineDb) Delete(data any, collectionName string, options LineDbAdapterO
|
||||
if db.indexStore != nil {
|
||||
opts := db.getCollectionOptions(collectionName)
|
||||
if opts != nil && len(opts.IndexedFields) > 0 {
|
||||
allRecords, readErr := adapter.Read(LineDbAdapterOptions{})
|
||||
allRecords, lineIdx, readErr := adapter.ReadWithPhysicalLineIndexes(LineDbAdapterOptions{})
|
||||
if readErr == nil {
|
||||
_ = db.indexStore.Rebuild(collectionName, DefaultPartition, opts.IndexedFields, allRecords)
|
||||
_ = db.indexStore.Rebuild(collectionName, DefaultPartition, opts.IndexedFields, allRecords, lineIdx)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -738,18 +813,18 @@ func (db *LineDb) indexRebuildTimerLoop(interval time.Duration) {
|
||||
if !strings.HasPrefix(name, baseName+"_") {
|
||||
continue
|
||||
}
|
||||
records, err := adapter.Read(LineDbAdapterOptions{})
|
||||
records, lineIdx, err := adapter.ReadWithPhysicalLineIndexes(LineDbAdapterOptions{})
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
_ = db.indexStore.Rebuild(opt.CollectionName, name, opt.IndexedFields, records)
|
||||
_ = db.indexStore.Rebuild(opt.CollectionName, name, opt.IndexedFields, records, lineIdx)
|
||||
}
|
||||
} else {
|
||||
adapter := db.adapters[opt.CollectionName]
|
||||
if adapter != nil {
|
||||
records, err := adapter.Read(LineDbAdapterOptions{})
|
||||
records, lineIdx, err := adapter.ReadWithPhysicalLineIndexes(LineDbAdapterOptions{})
|
||||
if err == nil {
|
||||
_ = db.indexStore.Rebuild(opt.CollectionName, DefaultPartition, opt.IndexedFields, records)
|
||||
_ = db.indexStore.Rebuild(opt.CollectionName, DefaultPartition, opt.IndexedFields, records, lineIdx)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1285,8 +1360,9 @@ func (db *LineDb) GetMaxID(records []any) int {
|
||||
for _, record := range records {
|
||||
if recordMap, ok := record.(map[string]any); ok {
|
||||
if id, ok := recordMap["id"]; ok {
|
||||
if idInt, ok := id.(int); ok && idInt > maxID {
|
||||
maxID = idInt
|
||||
n := idToIntForMax(id)
|
||||
if n > maxID {
|
||||
maxID = n
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1294,6 +1370,21 @@ func (db *LineDb) GetMaxID(records []any) int {
|
||||
return maxID
|
||||
}
|
||||
|
||||
func idToIntForMax(id any) int {
|
||||
switch v := id.(type) {
|
||||
case int:
|
||||
return v
|
||||
case int64:
|
||||
return int(v)
|
||||
case float64:
|
||||
return int(v)
|
||||
case float32:
|
||||
return int(v)
|
||||
default:
|
||||
return 0
|
||||
}
|
||||
}
|
||||
|
||||
func (db *LineDb) matchesFilter(record any, filter any, strictCompare bool) bool {
|
||||
if recordMap, ok := record.(map[string]any); ok {
|
||||
if filterMap, ok := filter.(map[string]any); ok {
|
||||
@@ -1383,10 +1474,32 @@ func (db *LineDb) isInvalidID(id any) bool {
|
||||
if id == nil {
|
||||
return true
|
||||
}
|
||||
if idNum, ok := id.(int); ok {
|
||||
return idNum <= -1
|
||||
}
|
||||
switch v := id.(type) {
|
||||
case int:
|
||||
return v <= -1
|
||||
case int8:
|
||||
return v <= -1
|
||||
case int16:
|
||||
return v <= -1
|
||||
case int32:
|
||||
return v <= -1
|
||||
case int64:
|
||||
return v <= -1
|
||||
case uint, uint8, uint16, uint32, uint64:
|
||||
return false
|
||||
case float32:
|
||||
if v != v { // NaN
|
||||
return true
|
||||
}
|
||||
return float64(v) <= -1
|
||||
case float64:
|
||||
if v != v { // NaN
|
||||
return true
|
||||
}
|
||||
return v <= -1
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
func (db *LineDb) compareIDs(a, b any) bool {
|
||||
@@ -1501,9 +1614,9 @@ func (db *LineDb) updatePartitioned(data any, collectionName string, filter any,
|
||||
}
|
||||
allResults = append(allResults, results...)
|
||||
if db.indexStore != nil && opts != nil && len(opts.IndexedFields) > 0 {
|
||||
records, readErr := adapter.Read(LineDbAdapterOptions{InTransaction: true})
|
||||
records, lineIdx, readErr := adapter.ReadWithPhysicalLineIndexes(LineDbAdapterOptions{InTransaction: true})
|
||||
if readErr == nil {
|
||||
_ = db.indexStore.Rebuild(collectionName, partitionName, opts.IndexedFields, records)
|
||||
_ = db.indexStore.Rebuild(collectionName, partitionName, opts.IndexedFields, records, lineIdx)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1538,9 +1651,9 @@ func (db *LineDb) deletePartitioned(data any, collectionName string, options Lin
|
||||
}
|
||||
allResults = append(allResults, results...)
|
||||
if db.indexStore != nil && opts != nil && len(opts.IndexedFields) > 0 {
|
||||
records, readErr := adapter.Read(LineDbAdapterOptions{InTransaction: true})
|
||||
records, lineIdx, readErr := adapter.ReadWithPhysicalLineIndexes(LineDbAdapterOptions{InTransaction: true})
|
||||
if readErr == nil {
|
||||
_ = db.indexStore.Rebuild(collectionName, partitionName, opts.IndexedFields, records)
|
||||
_ = db.indexStore.Rebuild(collectionName, partitionName, opts.IndexedFields, records, lineIdx)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,10 +4,11 @@
|
||||
package tests
|
||||
|
||||
import (
|
||||
"linedb/pkg/linedb"
|
||||
"os"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"direct-dev.ru/gitea/GiteaAdmin/elowdb-go/pkg/linedb"
|
||||
)
|
||||
|
||||
func setupPointUpdateDB(t *testing.T) (*linedb.LineDb, func()) {
|
||||
|
||||
@@ -27,8 +27,8 @@ func (f *failingLookupStore) UnindexRecord(collection, partition string, fields
|
||||
f.inner.UnindexRecord(collection, partition, fields, record, lineIndex)
|
||||
}
|
||||
|
||||
func (f *failingLookupStore) Rebuild(collection, partition string, fields []string, records []any) error {
|
||||
return f.inner.Rebuild(collection, partition, fields, records)
|
||||
func (f *failingLookupStore) Rebuild(collection, partition string, fields []string, records []any, lineIndexes []int) error {
|
||||
return f.inner.Rebuild(collection, partition, fields, records, lineIndexes)
|
||||
}
|
||||
|
||||
func (f *failingLookupStore) Clear(collection string) error {
|
||||
|
||||
Reference in New Issue
Block a user