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
2 changes: 1 addition & 1 deletion pkg/ingester/ingester_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ func (u *userTSDB) blocksToDelete(blocks []*tsdb.Block) map[ulid.ULID]struct{} {
// updateCachedShipperBlocks reads the shipper meta file and updates the cached shipped blocks.
func (u *userTSDB) updateCachedShippedBlocks() error {
shipperMeta, err := shipper.ReadMetaFile(u.db.Dir())
if os.IsNotExist(err) {
if os.IsNotExist(err) || os.IsNotExist(errors.Cause(err)) {
// If the meta file doesn't exist it means the shipper hasn't run yet.
shipperMeta = &shipper.Meta{}
} else if err != nil {
Expand Down
39 changes: 39 additions & 0 deletions pkg/ingester/ingester_v2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2475,6 +2475,45 @@ func TestIngester_seriesCountIsCorrectAfterClosingTSDBForDeletedTenant(t *testin
require.Equal(t, int64(0), i.TSDBState.seriesCount.Load())
}

func TestIngester_sholdUpdateCacheShippedBlocks(t *testing.T) {
ctx := context.Background()
cfg := defaultIngesterTestConfig(t)
cfg.LifecyclerConfig.JoinAfter = 0
cfg.BlocksStorageConfig.TSDB.ShipConcurrency = 2

// Create ingester
i, err := prepareIngesterWithBlocksStorage(t, cfg, nil)
require.NoError(t, err)

require.NoError(t, services.StartAndAwaitRunning(ctx, i))
defer services.StopAndAwaitTerminated(ctx, i) //nolint:errcheck

// Wait until it's ACTIVE
test.Poll(t, 1*time.Second, ring.ACTIVE, func() interface{} {
return i.lifecycler.GetState()
})

mockUserShipper(t, i)

// Mock the shipper meta (no blocks).
db := i.getTSDB(userID)
err = db.updateCachedShippedBlocks()
require.NoError(t, err)

require.Equal(t, len(db.getCachedShippedBlocks()), 0)
shippedBlock, _ := ulid.Parse("01D78XZ44G0000000000000000")

require.NoError(t, shipper.WriteMetaFile(log.NewNopLogger(), db.db.Dir(), &shipper.Meta{
Version: shipper.MetaVersion1,
Uploaded: []ulid.ULID{shippedBlock},
}))

err = db.updateCachedShippedBlocks()
require.NoError(t, err)

require.Equal(t, len(db.getCachedShippedBlocks()), 1)
}

func TestIngester_closeAndDeleteUserTSDBIfIdle_shouldNotCloseTSDBIfShippingIsInProgress(t *testing.T) {
ctx := context.Background()
cfg := defaultIngesterTestConfig(t)
Expand Down