@@ -110,6 +110,8 @@ func (*Driver) ID() string {
110
110
return DriverID
111
111
}
112
112
113
+ var errWriteConfigFile = errors .NewKind ("unable to write indexes configuration file" )
114
+
113
115
// Create a new index.
114
116
func (d * Driver ) Create (
115
117
db , table , id string ,
@@ -133,7 +135,7 @@ func (d *Driver) Create(
133
135
cfg := index .NewConfig (db , table , id , exprs , d .ID (), config )
134
136
err = index .WriteConfigFile (d .configFilePath (db , table , id ), cfg )
135
137
if err != nil {
136
- return nil , err
138
+ return nil , errWriteConfigFile . Wrap ( err )
137
139
}
138
140
139
141
idx , err := d .newPilosaIndex (db , table )
@@ -146,12 +148,14 @@ func (d *Driver) Create(
146
148
processingFile ,
147
149
[]byte {processingFileOnCreate },
148
150
); err != nil {
149
- return nil , err
151
+ return nil , errWriteConfigFile . Wrap ( err )
150
152
}
151
153
152
154
return newPilosaIndex (idx , cfg ), nil
153
155
}
154
156
157
+ var errReadIndexes = errors .NewKind ("error loading all indexes for table %s of database %s: %s" )
158
+
155
159
// LoadAll loads all indexes for given db and table
156
160
func (d * Driver ) LoadAll (db , table string ) ([]sql.Index , error ) {
157
161
var (
@@ -165,7 +169,7 @@ func (d *Driver) LoadAll(db, table string) ([]sql.Index, error) {
165
169
if os .IsNotExist (err ) {
166
170
return indexes , nil
167
171
}
168
- return nil , err
172
+ return nil , errReadIndexes . New ( table , db , err )
169
173
}
170
174
for _ , info := range dirs {
171
175
if info .IsDir () && ! strings .HasPrefix (info .Name (), "." ) {
@@ -187,6 +191,11 @@ func (d *Driver) LoadAll(db, table string) ([]sql.Index, error) {
187
191
return indexes , nil
188
192
}
189
193
194
+ var (
195
+ errLoadingIndexConfig = errors .NewKind ("unable to load index configuration" )
196
+ errReadIndexConfig = errors .NewKind ("unable to read index configuration" )
197
+ )
198
+
190
199
func (d * Driver ) loadIndex (db , table , id string ) (* pilosaIndex , error ) {
191
200
idx , err := d .newPilosaIndex (db , table )
192
201
if err != nil {
@@ -206,7 +215,7 @@ func (d *Driver) loadIndex(db, table, id string) (*pilosaIndex, error) {
206
215
processing := d .processingFilePath (db , table , id )
207
216
ok , err := index .ExistsProcessingFile (processing )
208
217
if err != nil {
209
- return nil , err
218
+ return nil , errLoadingIndexConfig . Wrap ( err )
210
219
}
211
220
if ok {
212
221
log := logrus .WithFields (logrus.Fields {
@@ -226,7 +235,7 @@ func (d *Driver) loadIndex(db, table, id string) (*pilosaIndex, error) {
226
235
227
236
cfg , err := index .ReadConfigFile (config )
228
237
if err != nil {
229
- return nil , err
238
+ return nil , errReadIndexConfig . Wrap ( err )
230
239
}
231
240
cfgDriver := cfg .Driver (DriverID )
232
241
if cfgDriver == nil {
@@ -382,13 +391,13 @@ func (d *Driver) Save(
382
391
[]byte {processingFileOnSave },
383
392
)
384
393
if err != nil {
385
- return err
394
+ return errWriteConfigFile . Wrap ( err )
386
395
}
387
396
388
397
cfgPath := d .configFilePath (i .Database (), i .Table (), i .ID ())
389
398
cfg , err := index .ReadConfigFile (cfgPath )
390
399
if err != nil {
391
- return err
400
+ return errReadIndexConfig . Wrap ( err )
392
401
}
393
402
driverCfg := cfg .Driver (DriverID )
394
403
@@ -462,7 +471,7 @@ func (d *Driver) Save(
462
471
return errors [0 ]
463
472
}
464
473
if err = index .WriteConfigFile (cfgPath , cfg ); err != nil {
465
- return err
474
+ return errWriteConfigFile . Wrap ( err )
466
475
}
467
476
468
477
observeIndex (time .Since (start ), timePilosa , timeMapping , rows )
0 commit comments