Skip to content

Commit 6399c38

Browse files
dinalDina Nimrodigtopper
authored
Development (#558)
* add retry if tsdb create schema fails (#555) * add retry if tsdb create schema fails * check for specific file not found error in get schema Co-authored-by: Dina Nimrodi <[email protected]> * Schema validation (#557) See https://iguazio.slack.com/archives/C010QF1UETX/p1625150730019000 Co-authored-by: Dina Nimrodi <[email protected]> Co-authored-by: Gal Topper <[email protected]>
1 parent 869b296 commit 6399c38

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

pkg/partmgr/partmgr.go

+16-2
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,21 @@ func (p *PartitionManager) ReadAndUpdateSchema() (err error) {
267267
return
268268
}
269269

270+
func unmarshalSchema(data []byte) (*config.Schema, error) {
271+
schemaInstance := &config.Schema{}
272+
err := json.Unmarshal(data, schemaInstance)
273+
if err != nil {
274+
return nil, err
275+
}
276+
if schemaInstance.TableSchemaInfo.PartitionerInterval == "" {
277+
return nil, errors.New("Schema partition interval may not be empty")
278+
}
279+
if schemaInstance.TableSchemaInfo.ChunckerInterval == "" {
280+
return nil, errors.New("Schema chunk interval may not be empty")
281+
}
282+
return schemaInstance, nil
283+
}
284+
270285
func (p *PartitionManager) updatePartitionsFromSchema(schema *config.Schema) error {
271286
if schema == nil {
272287
schemaFilePath := p.GetSchemaFilePath()
@@ -275,8 +290,7 @@ func (p *PartitionManager) updatePartitionsFromSchema(schema *config.Schema) err
275290
return errors.Wrapf(innerError, "Failed to read schema at path '%s'.", schemaFilePath)
276291
}
277292

278-
schema = &config.Schema{}
279-
innerError = json.Unmarshal(resp.Body(), schema)
293+
schema, innerError = unmarshalSchema(resp.Body())
280294
if innerError != nil {
281295
return errors.Wrapf(innerError, "Failed to unmarshal schema at path '%s'.", schemaFilePath)
282296
}

pkg/partmgr/partmgr_test.go

+14
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,20 @@ func TestNewPartitionMngrBadInput(t *testing.T) {
9696
assert.Error(t, err)
9797
}
9898

99+
func TestUnmarshalSchemaError(t *testing.T) {
100+
schemaString := []byte(`{}`)
101+
_, err := unmarshalSchema(schemaString)
102+
assert.Error(t, err)
103+
104+
schemaString = []byte(`{"tableSchemaInfo": {}}`)
105+
_, err = unmarshalSchema(schemaString)
106+
assert.Error(t, err)
107+
108+
schemaString = []byte(`{"tableSchemaInfo": {"PartitionerInterval": ""}}`)
109+
_, err = unmarshalSchema(schemaString)
110+
assert.Error(t, err)
111+
}
112+
99113
func TestPartsForRange(tst *testing.T) {
100114
numPartitions := 5
101115
manager := getPartitionManager(tst)

0 commit comments

Comments
 (0)