This commit is contained in:
GoEdgeLab
2024-07-27 15:42:50 +08:00
parent d511145bc5
commit c19be78e0d
524 changed files with 1817 additions and 1346 deletions
+3 -2
View File
@@ -1,11 +1,12 @@
// Copyright 2024 GoEdge CDN goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cn .
// Copyright 2024 GoEdge CDN goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cloud .
package kvstore
import (
"errors"
"github.com/cockroachdb/pebble"
"sync"
"github.com/cockroachdb/pebble"
)
type DB struct {
+3 -2
View File
@@ -1,12 +1,13 @@
// Copyright 2024 GoEdge CDN goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cn .
// Copyright 2024 GoEdge CDN goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cloud .
package kvstore_test
import (
"testing"
"github.com/TeaOSLab/EdgeNode/internal/utils/kvstore"
"github.com/TeaOSLab/EdgeNode/internal/utils/testutils"
"github.com/cockroachdb/pebble"
"testing"
)
func TestNewDB(t *testing.T) {
+2 -1
View File
@@ -1,10 +1,11 @@
// Copyright 2024 GoEdge CDN goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cn .
// Copyright 2024 GoEdge CDN goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cloud .
package kvstore
import (
"errors"
"fmt"
"github.com/cockroachdb/pebble"
)
+1 -1
View File
@@ -1,4 +1,4 @@
// Copyright 2024 GoEdge CDN goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cn .
// Copyright 2024 GoEdge CDN goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cloud .
package kvstore
+1 -1
View File
@@ -1,4 +1,4 @@
// Copyright 2024 GoEdge CDN goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cn .
// Copyright 2024 GoEdge CDN goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cloud .
package kvstore
+2 -1
View File
@@ -1,9 +1,10 @@
// Copyright 2024 GoEdge CDN goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cn .
// Copyright 2024 GoEdge CDN goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cloud .
package kvstore
import (
"fmt"
"github.com/TeaOSLab/EdgeNode/internal/remotelogs"
)
+1 -1
View File
@@ -1,4 +1,4 @@
// Copyright 2024 GoEdge CDN goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cn .
// Copyright 2024 GoEdge CDN goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cloud .
package kvstore
+10 -9
View File
@@ -1,4 +1,4 @@
// Copyright 2024 GoEdge CDN goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cn .
// Copyright 2024 GoEdge CDN goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cloud .
package kvstore
@@ -6,6 +6,7 @@ import (
"bytes"
"errors"
"fmt"
byteutils "github.com/TeaOSLab/EdgeNode/internal/utils/byte"
)
@@ -132,37 +133,37 @@ func (this *Query[T]) FieldOffset(fieldOffset []byte) *Query[T] {
return this
}
//func (this *Query[T]) FieldLt(value any) *Query[T] {
// func (this *Query[T]) FieldLt(value any) *Query[T] {
// this.fieldOperators = append(this.fieldOperators, QueryOperatorInfo{
// Operator: QueryOperatorLt,
// Value: value,
// })
// return this
//}
// }
//
//func (this *Query[T]) FieldLte(value any) *Query[T] {
// func (this *Query[T]) FieldLte(value any) *Query[T] {
// this.fieldOperators = append(this.fieldOperators, QueryOperatorInfo{
// Operator: QueryOperatorLte,
// Value: value,
// })
// return this
//}
// }
//
//func (this *Query[T]) FieldGt(value any) *Query[T] {
// func (this *Query[T]) FieldGt(value any) *Query[T] {
// this.fieldOperators = append(this.fieldOperators, QueryOperatorInfo{
// Operator: QueryOperatorGt,
// Value: value,
// })
// return this
//}
// }
//
//func (this *Query[T]) FieldGte(value any) *Query[T] {
// func (this *Query[T]) FieldGte(value any) *Query[T] {
// this.fieldOperators = append(this.fieldOperators, QueryOperatorInfo{
// Operator: QueryOperatorGte,
// Value: value,
// })
// return this
//}
// }
func (this *Query[T]) FindAll(fn IteratorFunc[T]) (err error) {
if this.table != nil && this.table.isClosed {
+8 -7
View File
@@ -1,14 +1,15 @@
// Copyright 2024 GoEdge CDN goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cn .
// Copyright 2024 GoEdge CDN goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cloud .
package kvstore_test
import (
"fmt"
"github.com/TeaOSLab/EdgeNode/internal/utils/kvstore"
"github.com/TeaOSLab/EdgeNode/internal/utils/testutils"
"runtime"
"testing"
"time"
"github.com/TeaOSLab/EdgeNode/internal/utils/kvstore"
"github.com/TeaOSLab/EdgeNode/internal/utils/testutils"
)
func TestQuery_FindAll(t *testing.T) {
@@ -228,8 +229,8 @@ func TestQuery_FindAll_Field(t *testing.T) {
err := table.
Query().
FieldAsc("expiresAt").
//KeysOnly().
//FieldLt(1710848959).
// KeysOnly().
// FieldLt(1710848959).
Limit(3).
FindAll(func(tx *kvstore.Tx[*testCachedItem], item kvstore.Item[*testCachedItem]) (goNext bool, err error) {
t.Log(item.Key, "=>", item.Value)
@@ -247,8 +248,8 @@ func TestQuery_FindAll_Field(t *testing.T) {
err := table.
Query().
FieldAsc("expiresAt").
//KeysOnly().
//FieldLt(1710848959).
// KeysOnly().
// FieldLt(1710848959).
FieldOffset(lastFieldKey).
Limit(3).
FindAll(func(tx *kvstore.Tx[*testCachedItem], item kvstore.Item[*testCachedItem]) (goNext bool, err error) {
+7 -6
View File
@@ -1,21 +1,22 @@
// Copyright 2024 GoEdge CDN goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cn .
// Copyright 2024 GoEdge CDN goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cloud .
package kvstore
import (
"errors"
"fmt"
"io"
"os"
"path/filepath"
"strings"
"sync"
"github.com/TeaOSLab/EdgeNode/internal/events"
"github.com/TeaOSLab/EdgeNode/internal/remotelogs"
fsutils "github.com/TeaOSLab/EdgeNode/internal/utils/fs"
memutils "github.com/TeaOSLab/EdgeNode/internal/utils/mem"
"github.com/cockroachdb/pebble"
"github.com/iwind/TeaGo/Tea"
"io"
"os"
"path/filepath"
"strings"
"sync"
)
const StoreSuffix = ".store"
+5 -4
View File
@@ -1,16 +1,17 @@
// Copyright 2024 GoEdge CDN goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cn .
// Copyright 2024 GoEdge CDN goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cloud .
package kvstore_test
import (
"sync"
"testing"
"time"
"github.com/TeaOSLab/EdgeNode/internal/utils/kvstore"
"github.com/cockroachdb/pebble"
"github.com/iwind/TeaGo/Tea"
"github.com/iwind/TeaGo/assert"
_ "github.com/iwind/TeaGo/bootstrap"
"sync"
"testing"
"time"
)
func TestMain(m *testing.M) {
+3 -2
View File
@@ -1,4 +1,4 @@
// Copyright 2024 GoEdge CDN goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cn .
// Copyright 2024 GoEdge CDN goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cloud .
package kvstore
@@ -7,9 +7,10 @@ import (
"encoding/binary"
"errors"
"fmt"
"sync"
"github.com/cockroachdb/pebble"
"github.com/iwind/TeaGo/types"
"sync"
)
const (
+1 -1
View File
@@ -1,4 +1,4 @@
// Copyright 2024 GoEdge CDN goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cn .
// Copyright 2024 GoEdge CDN goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cloud .
package kvstore
+3 -2
View File
@@ -1,11 +1,12 @@
// Copyright 2024 GoEdge CDN goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cn .
// Copyright 2024 GoEdge CDN goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cloud .
package kvstore_test
import (
"github.com/TeaOSLab/EdgeNode/internal/utils/kvstore"
"runtime"
"testing"
"github.com/TeaOSLab/EdgeNode/internal/utils/kvstore"
)
func TestCounterTable_Increase(t *testing.T) {
+1 -1
View File
@@ -1,4 +1,4 @@
// Copyright 2024 GoEdge CDN goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cn .
// Copyright 2024 GoEdge CDN goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cloud .
package kvstore
+7 -6
View File
@@ -1,16 +1,17 @@
// Copyright 2024 GoEdge CDN goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cn .
// Copyright 2024 GoEdge CDN goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cloud .
package kvstore_test
import (
"encoding/binary"
"errors"
"github.com/TeaOSLab/EdgeNode/internal/utils/fasttime"
"github.com/TeaOSLab/EdgeNode/internal/utils/kvstore"
"github.com/TeaOSLab/EdgeNode/internal/utils/testutils"
"strconv"
"testing"
"time"
"github.com/TeaOSLab/EdgeNode/internal/utils/fasttime"
"github.com/TeaOSLab/EdgeNode/internal/utils/kvstore"
"github.com/TeaOSLab/EdgeNode/internal/utils/testutils"
)
type testCachedItem struct {
@@ -103,7 +104,7 @@ func TestTable_AddField_Many(t *testing.T) {
return
}
//runtime.GOMAXPROCS(1)
// runtime.GOMAXPROCS(1)
var table = testOpenStoreTable[*testCachedItem](t, "cache_items", &testCacheItemEncoder[*testCachedItem]{})
@@ -161,7 +162,7 @@ func TestTable_AddField_Delete_Many(t *testing.T) {
return
}
//runtime.GOMAXPROCS(1)
// runtime.GOMAXPROCS(1)
var table = testOpenStoreTable[*testCachedItem](t, "cache_items", &testCacheItemEncoder[*testCachedItem]{})
+1 -1
View File
@@ -1,4 +1,4 @@
// Copyright 2024 GoEdge CDN goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cn .
// Copyright 2024 GoEdge CDN goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cloud .
package kvstore
+7 -6
View File
@@ -1,18 +1,19 @@
// Copyright 2024 GoEdge CDN goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cn .
// Copyright 2024 GoEdge CDN goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cloud .
package kvstore_test
import (
"fmt"
"github.com/TeaOSLab/EdgeNode/internal/utils/kvstore"
"github.com/TeaOSLab/EdgeNode/internal/utils/testutils"
"github.com/iwind/TeaGo/assert"
"github.com/iwind/TeaGo/types"
"math/rand"
"runtime"
"strconv"
"testing"
"time"
"github.com/TeaOSLab/EdgeNode/internal/utils/kvstore"
"github.com/TeaOSLab/EdgeNode/internal/utils/testutils"
"github.com/iwind/TeaGo/assert"
"github.com/iwind/TeaGo/types"
)
func TestTable_Set(t *testing.T) {
@@ -263,7 +264,7 @@ func TestTable_Count(t *testing.T) {
// watch memory usage
if testutils.IsSingleTesting() {
//time.Sleep(5 * time.Minute)
// time.Sleep(5 * time.Minute)
}
}
+2 -1
View File
@@ -1,10 +1,11 @@
// Copyright 2024 GoEdge CDN goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cn .
// Copyright 2024 GoEdge CDN goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cloud .
package kvstore
import (
"errors"
"fmt"
"github.com/cockroachdb/pebble"
)
+3 -2
View File
@@ -1,11 +1,12 @@
// Copyright 2024 GoEdge CDN goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cn .
// Copyright 2024 GoEdge CDN goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cloud .
package kvstore_test
import (
"fmt"
"github.com/TeaOSLab/EdgeNode/internal/utils/kvstore"
"testing"
"github.com/TeaOSLab/EdgeNode/internal/utils/kvstore"
)
func TestTable_ReadTx(t *testing.T) {
+1 -1
View File
@@ -1,4 +1,4 @@
// Copyright 2024 GoEdge CDN goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cn .
// Copyright 2024 GoEdge CDN goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cloud .
package kvstore
+3 -2
View File
@@ -1,13 +1,14 @@
// Copyright 2024 GoEdge CDN goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cn .
// Copyright 2024 GoEdge CDN goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cloud .
package kvstore_test
import (
"testing"
"github.com/TeaOSLab/EdgeNode/internal/utils/kvstore"
"github.com/iwind/TeaGo/Tea"
"github.com/iwind/TeaGo/assert"
_ "github.com/iwind/TeaGo/bootstrap"
"testing"
)
func TestRemoveDB(t *testing.T) {
+3 -3
View File
@@ -1,12 +1,13 @@
// Copyright 2024 GoEdge CDN goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cn .
// Copyright 2024 GoEdge CDN goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cloud .
package kvstore
import (
"encoding/binary"
"strconv"
"github.com/iwind/TeaGo/types"
"golang.org/x/exp/constraints"
"strconv"
)
type IntValueEncoder[T constraints.Integer] struct {
@@ -78,4 +79,3 @@ func (this *IntValueEncoder[T]) Decode(valueData []byte) (value T, err error) {
return
}
+1 -1
View File
@@ -1,4 +1,4 @@
// Copyright 2024 GoEdge CDN goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cn .
// Copyright 2024 GoEdge CDN goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cloud .
package kvstore
+1 -1
View File
@@ -1,4 +1,4 @@
// Copyright 2024 GoEdge CDN goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cn .
// Copyright 2024 GoEdge CDN goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cloud .
package kvstore
@@ -1,4 +1,4 @@
// Copyright 2024 GoEdge CDN goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cn .
// Copyright 2024 GoEdge CDN goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cloud .
package kvstore
+1 -1
View File
@@ -1,4 +1,4 @@
// Copyright 2024 GoEdge CDN goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cn .
// Copyright 2024 GoEdge CDN goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cloud .
package kvstore
@@ -1,4 +1,4 @@
// Copyright 2024 GoEdge CDN goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cn .
// Copyright 2024 GoEdge CDN goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cloud .
package kvstore
+3 -2
View File
@@ -1,11 +1,12 @@
// Copyright 2024 GoEdge CDN goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cn .
// Copyright 2024 GoEdge CDN goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cloud .
package kvstore_test
import (
"testing"
"github.com/TeaOSLab/EdgeNode/internal/utils/kvstore"
"github.com/iwind/TeaGo/assert"
"testing"
)
func TestStringValueEncoder_Encode(t *testing.T) {