@@ -2,8 +2,10 @@ package ingester
2
2
3
3
import (
4
4
"context"
5
+ "encoding/json"
5
6
"fmt"
6
7
"io"
8
+ "io/ioutil"
7
9
"math"
8
10
"net/http"
9
11
"os"
@@ -12,6 +14,7 @@ import (
12
14
"time"
13
15
14
16
"github.com/go-kit/kit/log/level"
17
+ "github.com/oklog/ulid"
15
18
"github.com/pkg/errors"
16
19
"github.com/prometheus/client_golang/prometheus"
17
20
"github.com/prometheus/client_golang/prometheus/promauto"
@@ -120,6 +123,38 @@ func (u *userTSDB) setLastUpdate(t time.Time) {
120
123
u .lastUpdate .Store (t .Unix ())
121
124
}
122
125
126
+ func (u * userTSDB ) getShippedBlocksULID () ([]ulid.ULID , error ) {
127
+ b , err := ioutil .ReadFile (filepath .Join (u .Dir (), shipper .MetaFilename ))
128
+ if err != nil {
129
+ return nil , errors .Wrap (err , "read shipper meta file" )
130
+ }
131
+ var shipperMeta shipper.Meta
132
+ if err := json .Unmarshal (b , & shipperMeta ); err != nil {
133
+ return nil , errors .Wrap (err , "unmarshal shipper meta file to json" )
134
+ }
135
+
136
+ return shipperMeta .Uploaded , nil
137
+ }
138
+
139
+ func (u * userTSDB ) getUnshippedBlocksULID () (unshipped []ulid.ULID , err error ) {
140
+ shippedBlocks , err := u .getShippedBlocksULID ()
141
+ if err != nil {
142
+ return nil , errors .Wrap (err , "get shipped blocks" )
143
+ }
144
+
145
+ Outer:
146
+ for _ , b := range u .Blocks () {
147
+ for _ , uid := range shippedBlocks {
148
+ if uid == b .Meta ().ULID {
149
+ continue Outer
150
+ }
151
+ }
152
+ unshipped = append (unshipped , b .Meta ().ULID )
153
+ }
154
+
155
+ return unshipped , nil
156
+ }
157
+
123
158
// TSDBState holds data structures used by the TSDB storage engine
124
159
type TSDBState struct {
125
160
dbs map [string ]* userTSDB // tsdb sharded by userID
0 commit comments