@@ -26,6 +26,7 @@ import (
26
26
"encoding/json"
27
27
"fmt"
28
28
"math"
29
+ "net/http"
29
30
pathUtil "path"
30
31
"path/filepath"
31
32
"strconv"
@@ -37,6 +38,7 @@ import (
37
38
"github.com/pkg/errors"
38
39
"github.com/v3io/v3io-go/pkg/dataplane"
39
40
"github.com/v3io/v3io-go/pkg/dataplane/http"
41
+ v3ioerrors "github.com/v3io/v3io-go/pkg/errors"
40
42
"github.com/v3io/v3io-tsdb/pkg/aggregate"
41
43
"github.com/v3io/v3io-tsdb/pkg/appender"
42
44
"github.com/v3io/v3io-tsdb/pkg/chunkenc"
@@ -95,14 +97,24 @@ func CreateTSDB(cfg *config.V3ioConfig, schema *config.Schema, container v3io.Co
95
97
96
98
path := pathUtil .Join (cfg .TablePath , config .SchemaConfigFileName )
97
99
// Check whether the config file already exists, and abort if it does
98
- _ , err = container .GetObjectSync (& v3io.GetObjectInput {Path : path , DataPlaneInput : dataPlaneInput })
99
- if err == nil {
100
- return fmt .Errorf ("A TSDB table already exists at path '" + cfg .TablePath + "'." )
101
- }
102
-
103
- err = container .PutObjectSync (& v3io.PutObjectInput {Path : path , Body : data , DataPlaneInput : dataPlaneInput })
104
- if err != nil {
105
- return errors .Wrapf (err , "Failed to create a TSDB schema at path '%s/%s/%s'." , cfg .WebAPIEndpoint , cfg .Container , path )
100
+ for i := 0 ; i < 8 ; i ++ {
101
+ _ , err = container .GetObjectSync (& v3io.GetObjectInput {Path : path , DataPlaneInput : dataPlaneInput })
102
+ if err == nil {
103
+ return fmt .Errorf ("A TSDB table already exists at path '" + cfg .TablePath + "'." )
104
+ } else if e , hasStatusCode := err .(v3ioerrors.ErrorWithStatusCode ); hasStatusCode && e .StatusCode () != http .StatusNotFound {
105
+ err = errors .Wrapf (err , "Failed to check TSDB schema at path '%s/%s/%s'." , cfg .WebAPIEndpoint , cfg .Container , path )
106
+ lgr .Error (err )
107
+ } else {
108
+ // if no tsdb schema found
109
+ err = container .PutObjectSync (& v3io.PutObjectInput {Path : path , Body : data , DataPlaneInput : dataPlaneInput })
110
+ if err != nil {
111
+ err = errors .Wrapf (err , "Failed to create a TSDB schema at path '%s/%s/%s'." , cfg .WebAPIEndpoint , cfg .Container , path )
112
+ lgr .Error (err )
113
+ } else {
114
+ lgr .Info ("Successfully created TSDB schema at path '%s/%s/%s'." , cfg .WebAPIEndpoint , cfg .Container , path )
115
+ break
116
+ }
117
+ }
106
118
}
107
119
return err
108
120
}
0 commit comments