Skip to content

Commit 3c231a1

Browse files
committed
fix ingester testcase
Signed-off-by: Ben Ye <[email protected]>
1 parent 5d677f5 commit 3c231a1

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

pkg/ingester/ingester.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,8 @@ type userTSDB struct {
256256
lastUpdate atomic.Int64
257257

258258
// Thanos shipper used to ship blocks to the storage.
259-
shipper Shipper
259+
shipper Shipper
260+
shipperMetadataFilePath string
260261

261262
// When deletion marker is found for the tenant (checked before shipping),
262263
// shipping stops and TSDB is closed before reaching idle timeout time (if enabled).
@@ -435,7 +436,7 @@ func (u *userTSDB) blocksToDelete(blocks []*tsdb.Block) map[ulid.ULID]struct{} {
435436

436437
// updateCachedShipperBlocks reads the shipper meta file and updates the cached shipped blocks.
437438
func (u *userTSDB) updateCachedShippedBlocks() error {
438-
shipperMeta, err := shipper.ReadMetaFile(u.db.Dir())
439+
shipperMeta, err := shipper.ReadMetaFile(u.shipperMetadataFilePath)
439440
if os.IsNotExist(err) || os.IsNotExist(errors.Cause(err)) {
440441
// If the meta file doesn't exist it means the shipper hasn't run yet.
441442
shipperMeta = &shipper.Meta{}
@@ -606,7 +607,7 @@ func newTSDBState(bucketClient objstore.Bucket, registerer prometheus.Registerer
606607
}
607608
}
608609

609-
// NewV2 returns a new Ingester that uses Cortex block storage instead of chunks storage.
610+
// New returns a new Ingester that uses Cortex block storage instead of chunks storage.
610611
func New(cfg Config, limits *validation.Overrides, registerer prometheus.Registerer, logger log.Logger) (*Ingester, error) {
611612
defaultInstanceLimits = &cfg.DefaultLimits
612613
if cfg.ingesterClientFactory == nil {
@@ -2052,6 +2053,7 @@ func (i *Ingester) createTSDB(userID string) (*userTSDB, error) {
20522053
metadata.NoneFunc,
20532054
"",
20542055
)
2056+
userDB.shipperMetadataFilePath = filepath.Join(userDB.db.Dir(), filepath.Clean(shipper.DefaultMetaFilename))
20552057

20562058
// Initialise the shipper blocks cache.
20572059
if err := userDB.updateCachedShippedBlocks(); err != nil {

pkg/ingester/ingester_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2821,7 +2821,7 @@ func TestIngester_sholdUpdateCacheShippedBlocks(t *testing.T) {
28212821
require.Equal(t, len(db.getCachedShippedBlocks()), 0)
28222822
shippedBlock, _ := ulid.Parse("01D78XZ44G0000000000000000")
28232823

2824-
require.NoError(t, shipper.WriteMetaFile(log.NewNopLogger(), db.db.Dir(), &shipper.Meta{
2824+
require.NoError(t, shipper.WriteMetaFile(log.NewNopLogger(), db.shipperMetadataFilePath, &shipper.Meta{
28252825
Version: shipper.MetaVersion1,
28262826
Uploaded: []ulid.ULID{shippedBlock},
28272827
}))
@@ -2858,7 +2858,7 @@ func TestIngester_closeAndDeleteUserTSDBIfIdle_shouldNotCloseTSDBIfShippingIsInP
28582858

28592859
// Mock the shipper meta (no blocks).
28602860
db := i.getTSDB(userID)
2861-
require.NoError(t, shipper.WriteMetaFile(log.NewNopLogger(), db.db.Dir(), &shipper.Meta{
2861+
require.NoError(t, shipper.WriteMetaFile(log.NewNopLogger(), db.shipperMetadataFilePath, &shipper.Meta{
28622862
Version: shipper.MetaVersion1,
28632863
}))
28642864

@@ -3788,7 +3788,7 @@ func TestIngesterNotDeleteUnshippedBlocks(t *testing.T) {
37883788
`, oldBlocks[0].Meta().ULID.Time()/1000)), "cortex_ingester_oldest_unshipped_block_timestamp_seconds"))
37893789

37903790
// Saying that we have shipped the second block, so only that should get deleted.
3791-
require.Nil(t, shipper.WriteMetaFile(nil, db.db.Dir(), &shipper.Meta{
3791+
require.Nil(t, shipper.WriteMetaFile(nil, db.shipperMetadataFilePath, &shipper.Meta{
37923792
Version: shipper.MetaVersion1,
37933793
Uploaded: []ulid.ULID{oldBlocks[1].Meta().ULID},
37943794
}))
@@ -3816,7 +3816,7 @@ func TestIngesterNotDeleteUnshippedBlocks(t *testing.T) {
38163816
`, newBlocks[0].Meta().ULID.Time()/1000)), "cortex_ingester_oldest_unshipped_block_timestamp_seconds"))
38173817

38183818
// Shipping 2 more blocks, hence all the blocks from first round.
3819-
require.Nil(t, shipper.WriteMetaFile(nil, db.db.Dir(), &shipper.Meta{
3819+
require.Nil(t, shipper.WriteMetaFile(nil, db.shipperMetadataFilePath, &shipper.Meta{
38203820
Version: shipper.MetaVersion1,
38213821
Uploaded: []ulid.ULID{oldBlocks[1].Meta().ULID, newBlocks[0].Meta().ULID, newBlocks[1].Meta().ULID},
38223822
}))

0 commit comments

Comments
 (0)