Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion archive/archive.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,8 @@ func (a *archive) check(ctx context.Context) error {
skip++
continue
}
return err
a.stat.archiveError.Add(1)
return indexStore.MarkError(ctx, spaceId, err.Error())
}
log.Info("space is archived", zap.String("spaceId", spaceId), zap.Duration("dur", time.Since(st)))
if !deadline.IsZero() && deadline.Sub(time.Now()) < time.Minute*10 {
Expand Down
12 changes: 10 additions & 2 deletions archive/stat.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ import (
)

type archiveStat struct {
archived atomic.Uint32
restored atomic.Uint32
archived atomic.Uint32
archiveError atomic.Uint32
restored atomic.Uint32
}

func registerMetric(s *archiveStat, registry *prometheus.Registry) {
Expand All @@ -26,4 +27,11 @@ func registerMetric(s *archiveStat, registry *prometheus.Registry) {
}, func() float64 {
return float64(s.restored.Load())
}))
registry.MustRegister(prometheus.NewGaugeFunc(prometheus.GaugeOpts{
Namespace: "node",
Subsystem: "archive",
Name: "error",
}, func() float64 {
return float64(s.archiveError.Load())
}))
}
12 changes: 12 additions & 0 deletions nodestorage/indexstorage.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const (
SpaceStatusRemove
SpaceStatusRemovePrepare
SpaceStatusArchived
SpaceStatusError
)

var (
Expand All @@ -41,6 +42,7 @@ const (
valueKey = "v"
archiveSizeCompressedKey = "asc"
archiveSizeUncompressedKey = "asu"
errorKey = "err"
diffMigrationKey = "diffState"
diffVersionKey = "diffVersion"

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

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

func (d *indexStorage) MarkError(ctx context.Context, spaceId string, errString string) (err error) {
_, err = d.spaceColl.UpdateId(ctx, spaceId, query.ModifyFunc(func(a *anyenc.Arena, v *anyenc.Value) (result *anyenc.Value, modified bool, err error) {
v.Set(statusKey, a.NewNumberInt(int(SpaceStatusError)))
v.Set(errorKey, a.NewString(errString))
return v, true, nil
}))
return err
}

func (d *indexStorage) MarkArchived(ctx context.Context, spaceId string, compressedSize, uncompressedSize int64) (err error) {
_, err = d.spaceColl.UpdateId(ctx, spaceId, query.ModifyFunc(func(a *anyenc.Arena, v *anyenc.Value) (result *anyenc.Value, modified bool, err error) {
v.Set(archiveSizeCompressedKey, a.NewNumberInt(int(compressedSize)))
Expand Down
26 changes: 26 additions & 0 deletions nodestorage/indexstorage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,3 +100,29 @@ func Test_migrateToSingleCollection(t *testing.T) {
assert.Contains(t, collNames, spaceCollName)
assert.Contains(t, collNames, settingsCollName)
}

func TestIndexStorage_MarkArchived(t *testing.T) {
tempDir := t.TempDir()
fx, err := createTestIndexStorage(ctx, tempDir)
require.NoError(t, err)
defer fx.Close()

require.NoError(t, fx.SetSpaceStatus(ctx, "space1", SpaceStatusOk, ""))
require.NoError(t, fx.MarkArchived(ctx, "space1", 1, 2))
status, err := fx.SpaceStatus(ctx, "space1")
require.NoError(t, err)
assert.Equal(t, SpaceStatusArchived, status)
}

func TestIndexStorage_MarkError(t *testing.T) {
tempDir := t.TempDir()
fx, err := createTestIndexStorage(ctx, tempDir)
require.NoError(t, err)
defer fx.Close()

require.NoError(t, fx.SetSpaceStatus(ctx, "space1", SpaceStatusOk, ""))
require.NoError(t, fx.MarkError(ctx, "space1", "error"))
status, err := fx.SpaceStatus(ctx, "space1")
require.NoError(t, err)
assert.Equal(t, SpaceStatusError, status)
}
14 changes: 14 additions & 0 deletions nodestorage/mock_nodestorage/mock_nodestorage.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading