MCPcopy Create free account
hub / github.com/bytebase/bytebase / getIndices

Method getIndices

backend/plugin/db/elasticsearch/sync.go:205–337  ·  view source on GitHub ↗
(ctx context.Context)

Source from the content-addressed store, hash-verified

203}
204
205func (d *Driver) getIndices(ctx context.Context) ([]*storepb.TableMetadata, error) {
206 var indicesMetadata []*storepb.TableMetadata
207
208 // Get hidden indices to filter them out.
209 hiddenIndices, err := d.getHiddenIndices(ctx)
210 if err != nil {
211 return nil, errors.Wrap(err, "failed to get hidden indices")
212 }
213
214 if d.isOpenSearch && d.opensearchAPI != nil {
215 resp, err := d.opensearchAPI.Cat.Indices(ctx, &opensearchapi.CatIndicesReq{})
216 if err != nil {
217 return nil, errors.Wrapf(err, "failed to list indices")
218 }
219
220 for _, idx := range resp.Indices {
221 if hiddenIndices[idx.Index] {
222 continue
223 }
224
225 var datasize int64
226 if idx.StoreSize != nil {
227 datasize, err = unitConversion(*idx.StoreSize)
228 if err != nil {
229 return nil, err
230 }
231 }
232
233 var docCount int64
234 if idx.DocsCount != nil {
235 docCount = int64(*idx.DocsCount)
236 }
237
238 indicesMetadata = append(indicesMetadata, &storepb.TableMetadata{
239 Name: idx.Index,
240 DataSize: datasize,
241 RowCount: docCount,
242 })
243 }
244
245 return indicesMetadata, nil
246 } else if d.typedClient != nil {
247 res, err := esapi.CatIndicesRequest{Format: "json", Pretty: true}.Do(ctx, d.typedClient)
248 if err != nil {
249 return nil, errors.Wrapf(err, "failed to list indices")
250 }
251
252 bytes, err := readBytesAndClose(res)
253 if err != nil {
254 return nil, errors.Wrap(err, "failed to list Elasticsearch indices")
255 }
256
257 var results []IndicesResult
258 if err := json.Unmarshal(bytes, &results); err != nil {
259 // Include response body to help debug parsing issues
260 bodyPreview, truncated := common.TruncateString(string(bytes), 500)
261 if truncated {
262 bodyPreview += "..."

Callers 1

SyncDBSchemaMethod · 0.95

Implementers 15

MockDriverbackend/plugin/advisor/utils_for_tests
Driverbackend/plugin/db/bigquery/bigquery.go
Driverbackend/plugin/db/mongodb/mongodb.go
Driverbackend/plugin/db/trino/trino.go
Driverbackend/plugin/db/redshift/redshift.go
Driverbackend/plugin/db/oracle/oracle.go
Driverbackend/plugin/db/dynamodb/dynamodb.go
Driverbackend/plugin/db/cosmosdb/cosmosdb.go
Driverbackend/plugin/db/spanner/spanner.go
Driverbackend/plugin/db/mssql/mssql.go
Driverbackend/plugin/db/mysql/mysql.go
Driverbackend/plugin/db/pg/pg.go

Calls 9

getHiddenIndicesMethod · 0.95
TruncateStringFunction · 0.92
unitConversionFunction · 0.85
readBytesAndCloseFunction · 0.85
parseDocCountFunction · 0.85
DoMethod · 0.80
UnmarshalMethod · 0.80
ErrorfMethod · 0.80
CloseMethod · 0.65

Tested by

no test coverage detected