Skip to content

Commit 0e99f42

Browse files
authored
Merge pull request #195 from anyproto/GO-4043-archive-cold-spaces
GO-4043 space status error
2 parents 272529a + b27f415 commit 0e99f42

File tree

5 files changed

+64
-3
lines changed

5 files changed

+64
-3
lines changed

archive/archive.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,8 @@ func (a *archive) check(ctx context.Context) error {
267267
skip++
268268
continue
269269
}
270-
return err
270+
a.stat.archiveError.Add(1)
271+
return indexStore.MarkError(ctx, spaceId, err.Error())
271272
}
272273
log.Info("space is archived", zap.String("spaceId", spaceId), zap.Duration("dur", time.Since(st)))
273274
if !deadline.IsZero() && deadline.Sub(time.Now()) < time.Minute*10 {

archive/stat.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@ import (
77
)
88

99
type archiveStat struct {
10-
archived atomic.Uint32
11-
restored atomic.Uint32
10+
archived atomic.Uint32
11+
archiveError atomic.Uint32
12+
restored atomic.Uint32
1213
}
1314

1415
func registerMetric(s *archiveStat, registry *prometheus.Registry) {
@@ -26,4 +27,11 @@ func registerMetric(s *archiveStat, registry *prometheus.Registry) {
2627
}, func() float64 {
2728
return float64(s.restored.Load())
2829
}))
30+
registry.MustRegister(prometheus.NewGaugeFunc(prometheus.GaugeOpts{
31+
Namespace: "node",
32+
Subsystem: "archive",
33+
Name: "error",
34+
}, func() float64 {
35+
return float64(s.archiveError.Load())
36+
}))
2937
}

nodestorage/indexstorage.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ const (
2222
SpaceStatusRemove
2323
SpaceStatusRemovePrepare
2424
SpaceStatusArchived
25+
SpaceStatusError
2526
)
2627

2728
var (
@@ -41,6 +42,7 @@ const (
4142
valueKey = "v"
4243
archiveSizeCompressedKey = "asc"
4344
archiveSizeUncompressedKey = "asu"
45+
errorKey = "err"
4446
diffMigrationKey = "diffState"
4547
diffVersionKey = "diffVersion"
4648

@@ -54,6 +56,7 @@ type IndexStorage interface {
5456
SetSpaceStatus(ctx context.Context, spaceId string, status SpaceStatus, recId string) (err error)
5557
SpaceStatus(ctx context.Context, spaceId string) (status SpaceStatus, err error)
5658
MarkArchived(ctx context.Context, spaceId string, compressedSize, uncompressedSize int64) (err error)
59+
MarkError(ctx context.Context, spaceId string, errString string) (err error)
5760
LastRecordId(ctx context.Context) (id string, err error)
5861
FindOldestInactiveSpace(ctx context.Context, olderThan time.Duration, skip int) (spaceId string, err error)
5962

@@ -183,6 +186,15 @@ func (d *indexStorage) SetSpaceStatus(ctx context.Context, spaceId string, statu
183186
return tx.Commit()
184187
}
185188

189+
func (d *indexStorage) MarkError(ctx context.Context, spaceId string, errString string) (err error) {
190+
_, err = d.spaceColl.UpdateId(ctx, spaceId, query.ModifyFunc(func(a *anyenc.Arena, v *anyenc.Value) (result *anyenc.Value, modified bool, err error) {
191+
v.Set(statusKey, a.NewNumberInt(int(SpaceStatusError)))
192+
v.Set(errorKey, a.NewString(errString))
193+
return v, true, nil
194+
}))
195+
return err
196+
}
197+
186198
func (d *indexStorage) MarkArchived(ctx context.Context, spaceId string, compressedSize, uncompressedSize int64) (err error) {
187199
_, err = d.spaceColl.UpdateId(ctx, spaceId, query.ModifyFunc(func(a *anyenc.Arena, v *anyenc.Value) (result *anyenc.Value, modified bool, err error) {
188200
v.Set(archiveSizeCompressedKey, a.NewNumberInt(int(compressedSize)))

nodestorage/indexstorage_test.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,3 +100,29 @@ func Test_migrateToSingleCollection(t *testing.T) {
100100
assert.Contains(t, collNames, spaceCollName)
101101
assert.Contains(t, collNames, settingsCollName)
102102
}
103+
104+
func TestIndexStorage_MarkArchived(t *testing.T) {
105+
tempDir := t.TempDir()
106+
fx, err := createTestIndexStorage(ctx, tempDir)
107+
require.NoError(t, err)
108+
defer fx.Close()
109+
110+
require.NoError(t, fx.SetSpaceStatus(ctx, "space1", SpaceStatusOk, ""))
111+
require.NoError(t, fx.MarkArchived(ctx, "space1", 1, 2))
112+
status, err := fx.SpaceStatus(ctx, "space1")
113+
require.NoError(t, err)
114+
assert.Equal(t, SpaceStatusArchived, status)
115+
}
116+
117+
func TestIndexStorage_MarkError(t *testing.T) {
118+
tempDir := t.TempDir()
119+
fx, err := createTestIndexStorage(ctx, tempDir)
120+
require.NoError(t, err)
121+
defer fx.Close()
122+
123+
require.NoError(t, fx.SetSpaceStatus(ctx, "space1", SpaceStatusOk, ""))
124+
require.NoError(t, fx.MarkError(ctx, "space1", "error"))
125+
status, err := fx.SpaceStatus(ctx, "space1")
126+
require.NoError(t, err)
127+
assert.Equal(t, SpaceStatusError, status)
128+
}

nodestorage/mock_nodestorage/mock_nodestorage.go

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)