@@ -41,19 +41,7 @@ func NewPartitionMngr(cfg *config.Schema, partPath string, cont *v3io.Container)
41
41
return nil , err
42
42
}
43
43
newMngr := & PartitionManager {cfg : cfg , path : partPath , cyclic : false , container : cont , currentPartitionInterval : currentPartitionInterval }
44
- for _ , part := range cfg .Partitions {
45
- partPath := path .Join (newMngr .path , strconv .FormatInt (part .StartTime / 1000 , 10 )) + "/"
46
- newPart , err := NewDBPartition (newMngr , part .StartTime , partPath )
47
- if err != nil {
48
- return nil , err
49
- }
50
- newMngr .partitions = append (newMngr .partitions , newPart )
51
- if newMngr .headPartition == nil {
52
- newMngr .headPartition = newPart
53
- } else if newMngr .headPartition .startTime < newPart .startTime {
54
- newMngr .headPartition = newPart
55
- }
56
- }
44
+ newMngr .updatePartitions (cfg )
57
45
return newMngr , nil
58
46
}
59
47
@@ -193,6 +181,41 @@ func (p *PartitionManager) updatePartitionInSchema(partition *DBPartition) error
193
181
return err
194
182
}
195
183
184
+ func (p * PartitionManager ) ReadAndUpdateSchema () error {
185
+ fullPath := path .Join (p .path , config .SCHEMA_CONFIG )
186
+ resp , err := p .container .Sync .GetObject (& v3io.GetObjectInput {Path : fullPath })
187
+ if err != nil {
188
+ return errors .Wrap (err , "Failed to read schema at path: " + fullPath )
189
+ }
190
+
191
+ schema := config.Schema {}
192
+ err = json .Unmarshal (resp .Body (), & schema )
193
+ if err != nil {
194
+ return errors .Wrap (err , "Failed to Unmarshal schema at path: " + fullPath )
195
+ }
196
+ p .cfg = & schema
197
+ p .updatePartitions (& schema )
198
+ return nil
199
+ }
200
+
201
+ func (p * PartitionManager ) updatePartitions (schema * config.Schema ) error {
202
+ p .partitions = []* DBPartition {}
203
+ for _ , part := range schema .Partitions {
204
+ partPath := path .Join (p .path , strconv .FormatInt (part .StartTime / 1000 , 10 )) + "/"
205
+ newPart , err := NewDBPartition (p , part .StartTime , partPath )
206
+ if err != nil {
207
+ return err
208
+ }
209
+ p .partitions = append (p .partitions , newPart )
210
+ if p .headPartition == nil {
211
+ p .headPartition = newPart
212
+ } else if p .headPartition .startTime < newPart .startTime {
213
+ p .headPartition = newPart
214
+ }
215
+ }
216
+ return nil
217
+ }
218
+
196
219
func (p * PartitionManager ) PartsForRange (mint , maxt int64 ) []* DBPartition {
197
220
var parts []* DBPartition
198
221
for _ , part := range p .partitions {
0 commit comments