Skip to content

Commit e555faf

Browse files
authored
fix(simplefs): race condition and get issue (#32)
* fix(simplefs): race condition and get issue * fix(ci): golangci-lint * fix(race-condition): simplefs start storage * fix(badger): handle in-memory directive * hotfix(go-redis): list keys * fix(go-redis): panic on range inexistant keys * release(v0.0.15) * fix(ci): golangci-lint * fix(caddyfile): use configuration block
1 parent a05901d commit e555faf

File tree

25 files changed

+102
-52
lines changed

25 files changed

+102
-52
lines changed

badger/badger.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ import (
1515

1616
"dario.cat/mergo"
1717
"github.com/darkweak/storages/core"
18-
badger "github.com/dgraph-io/badger/v3"
19-
lz4 "github.com/pierrec/lz4/v4"
18+
"github.com/dgraph-io/badger/v3"
19+
"github.com/pierrec/lz4/v4"
2020
"go.uber.org/zap"
2121
)
2222

@@ -58,10 +58,7 @@ func Factory(badgerConfiguration core.CacheProvider, logger core.Logger, stale t
5858
logger.Error("An error occurred during the badgerOptions merge from the default options with your configuration.")
5959
}
6060

61-
if badgerOptions.InMemory {
62-
badgerOptions.Dir = ""
63-
badgerOptions.ValueDir = ""
64-
} else {
61+
if !badgerOptions.InMemory {
6562
if badgerOptions.Dir == "" {
6663
badgerOptions.Dir = "souin_dir"
6764
}

badger/caddy/badger.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ package caddy
55
import (
66
"net/http"
77

8-
caddy "github.com/caddyserver/caddy/v2"
8+
"github.com/caddyserver/caddy/v2"
99
"github.com/caddyserver/caddy/v2/modules/caddyhttp"
1010
"github.com/darkweak/storages/badger"
1111
"github.com/darkweak/storages/core"

badger/caddy/go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ go 1.22.1
44

55
require (
66
github.com/caddyserver/caddy/v2 v2.8.4
7-
github.com/darkweak/storages/badger v0.0.14
8-
github.com/darkweak/storages/core v0.0.14
7+
github.com/darkweak/storages/badger v0.0.15
8+
github.com/darkweak/storages/core v0.0.15
99
)
1010

1111
require (

badger/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ go 1.22.1
44

55
require (
66
dario.cat/mergo v1.0.1
7-
github.com/darkweak/storages/core v0.0.14
7+
github.com/darkweak/storages/core v0.0.15
88
github.com/dgraph-io/badger/v3 v3.2103.5
99
github.com/pierrec/lz4/v4 v4.1.22
1010
go.uber.org/zap v1.27.0

core/core.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,9 @@ type CacheProvider struct {
4242
}
4343

4444
const (
45-
DISABLE_VARY_CTX = "storages_bypass_vary"
46-
MappingKeyPrefix = "IDX_"
45+
DISABLE_VARY_CTX = "storages_bypass_vary"
46+
MappingKeyPrefix = "IDX_"
47+
SurrogateKeyPrefix = "SURROGATE_"
4748
)
4849

4950
func DecodeMapping(item []byte) (*StorageMapper, error) {

etcd/caddy/go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ go 1.22.1
44

55
require (
66
github.com/caddyserver/caddy/v2 v2.8.4
7-
github.com/darkweak/storages/core v0.0.14
8-
github.com/darkweak/storages/etcd v0.0.14
7+
github.com/darkweak/storages/core v0.0.15
8+
github.com/darkweak/storages/etcd v0.0.15
99
)
1010

1111
require (

etcd/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ go 1.22.1
55
replace github.com/darkweak/storages/core => ../core
66

77
require (
8-
github.com/darkweak/storages/core v0.0.14
8+
github.com/darkweak/storages/core v0.0.15
99
github.com/pierrec/lz4/v4 v4.1.22
1010
go.etcd.io/etcd/client/v3 v3.5.18
1111
go.uber.org/zap v1.27.0

go-redis/caddy/go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ go 1.22.1
44

55
require (
66
github.com/caddyserver/caddy/v2 v2.8.4
7-
github.com/darkweak/storages/core v0.0.14
8-
github.com/darkweak/storages/go-redis v0.0.14
7+
github.com/darkweak/storages/core v0.0.15
8+
github.com/darkweak/storages/go-redis v0.0.15
99
)
1010

1111
require (

go-redis/go-redis.go

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ import (
1313
"time"
1414

1515
"github.com/darkweak/storages/core"
16-
lz4 "github.com/pierrec/lz4/v4"
17-
redis "github.com/redis/go-redis/v9"
16+
"github.com/pierrec/lz4/v4"
17+
"github.com/redis/go-redis/v9"
1818
)
1919

2020
// Redis provider type.
@@ -121,9 +121,22 @@ func (provider *Redis) ListKeys() []string {
121121

122122
keys := []string{}
123123

124-
iter := provider.inClient.Scan(provider.ctx, 0, "*", 0).Iterator()
124+
iter := provider.inClient.Scan(provider.ctx, 0, provider.hashtags+core.MappingKeyPrefix+"*", 0).Iterator()
125125
for iter.Next(provider.ctx) {
126-
keys = append(keys, iter.Val())
126+
value := provider.Get(iter.Val())
127+
128+
mapping, err := core.DecodeMapping(value)
129+
if err != nil {
130+
continue
131+
}
132+
133+
for _, v := range mapping.GetMapping() {
134+
if v.GetFreshTime().AsTime().Before(time.Now()) && v.GetStaleTime().AsTime().Before(time.Now()) {
135+
continue
136+
}
137+
138+
keys = append(keys, v.GetRealKey())
139+
}
127140
}
128141

129142
if err := iter.Err(); err != nil {
@@ -160,7 +173,10 @@ func (provider *Redis) MapKeys(prefix string) map[string]string {
160173

161174
for idx, item := range keys {
162175
k, _ := strings.CutPrefix(item, prefix)
163-
mapKeys[k] = vals[idx].(string)
176+
177+
if vals[idx] != nil {
178+
mapKeys[k] = vals[idx].(string)
179+
}
164180
}
165181

166182
return mapKeys

go-redis/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ go 1.22.1
55
replace github.com/darkweak/storages/core => ../core
66

77
require (
8-
github.com/darkweak/storages/core v0.0.14
8+
github.com/darkweak/storages/core v0.0.15
99
github.com/pierrec/lz4/v4 v4.1.22
1010
github.com/redis/go-redis/v9 v9.7.1
1111
go.uber.org/zap v1.27.0

0 commit comments

Comments
 (0)