-
Notifications
You must be signed in to change notification settings - Fork 4.9k
/
data_files.go
49 lines (40 loc) · 1.58 KB
/
data_files.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
// or more contributor license agreements. Licensed under the Elastic License;
// you may not use this file except in compliance with the Elastic License.
package tablespace
import (
"context"
"database/sql"
"fmt"
)
type dataFile struct {
FileName sql.NullString
FileID sql.NullInt64
TablespaceName sql.NullString
FileSizeBytes sql.NullInt64
Status sql.NullString
MaxFileSizeBytes sql.NullInt64
AvailableForUserBytes sql.NullInt64
OnlineStatus sql.NullString
}
func (d *dataFile) hash() string {
return fmt.Sprintf("%s%d", d.TablespaceName.String, d.FileID.Int64)
}
func (d *dataFile) eventKey() string {
return d.TablespaceName.String
}
func (e *tablespaceExtractor) dataFilesData(ctx context.Context) ([]dataFile, error) {
rows, err := e.db.QueryContext(ctx, "SELECT FILE_NAME, FILE_ID, TABLESPACE_NAME, BYTES, STATUS, MAXBYTES, USER_BYTES, ONLINE_STATUS FROM SYS.DBA_DATA_FILES UNION SELECT FILE_NAME, FILE_ID, TABLESPACE_NAME, BYTES, STATUS, MAXBYTES, USER_BYTES, STATUS AS ONLINE_STATUS FROM SYS.DBA_TEMP_FILES")
if err != nil {
return nil, fmt.Errorf("error executing query: %w", err)
}
results := make([]dataFile, 0)
for rows.Next() {
dest := dataFile{}
if err = rows.Scan(&dest.FileName, &dest.FileID, &dest.TablespaceName, &dest.FileSizeBytes, &dest.Status, &dest.MaxFileSizeBytes, &dest.AvailableForUserBytes, &dest.OnlineStatus); err != nil {
return nil, err
}
results = append(results, dest)
}
return results, nil
}