2015-08-22 00:23:01 +00:00
|
|
|
package state
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/hashicorp/go-memdb"
|
|
|
|
)
|
|
|
|
|
2021-01-30 00:24:41 +00:00
|
|
|
// newDBSchema creates and returns the memdb schema for the Store.
|
|
|
|
func newDBSchema() *memdb.DBSchema {
|
|
|
|
db := &memdb.DBSchema{Tables: make(map[string]*memdb.TableSchema)}
|
2015-08-22 00:23:01 +00:00
|
|
|
|
2021-01-30 00:24:41 +00:00
|
|
|
addTableSchemas(db,
|
|
|
|
authMethodsTableSchema,
|
|
|
|
autopilotConfigTableSchema,
|
|
|
|
bindingRulesTableSchema,
|
|
|
|
caBuiltinProviderTableSchema,
|
|
|
|
caConfigTableSchema,
|
|
|
|
caRootTableSchema,
|
|
|
|
checksTableSchema,
|
|
|
|
configTableSchema,
|
|
|
|
coordinatesTableSchema,
|
|
|
|
federationStateTableSchema,
|
|
|
|
gatewayServicesTableSchema,
|
|
|
|
indexTableSchema,
|
|
|
|
intentionsTableSchema,
|
|
|
|
kvsTableSchema,
|
|
|
|
meshTopologyTableSchema,
|
|
|
|
nodesTableSchema,
|
|
|
|
policiesTableSchema,
|
|
|
|
preparedQueriesTableSchema,
|
|
|
|
rolesTableSchema,
|
|
|
|
servicesTableSchema,
|
|
|
|
sessionChecksTableSchema,
|
|
|
|
sessionsTableSchema,
|
|
|
|
systemMetadataTableSchema,
|
|
|
|
tokensTableSchema,
|
|
|
|
tombstonesTableSchema,
|
|
|
|
usageTableSchema,
|
|
|
|
)
|
|
|
|
withEnterpriseSchema(db)
|
|
|
|
return db
|
2017-11-29 01:03:34 +00:00
|
|
|
}
|
|
|
|
|
2021-01-30 00:24:41 +00:00
|
|
|
func addTableSchemas(db *memdb.DBSchema, schemas ...func() *memdb.TableSchema) {
|
2015-08-22 00:23:01 +00:00
|
|
|
for _, fn := range schemas {
|
|
|
|
schema := fn()
|
|
|
|
if _, ok := db.Tables[schema.Name]; ok {
|
|
|
|
panic(fmt.Sprintf("duplicate table name: %s", schema.Name))
|
|
|
|
}
|
|
|
|
db.Tables[schema.Name] = schema
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-05 22:45:27 +00:00
|
|
|
// IndexEntry keeps a record of the last index of a table or entity within a table.
|
|
|
|
type IndexEntry struct {
|
|
|
|
Key string
|
|
|
|
Value uint64
|
|
|
|
}
|
|
|
|
|
2021-02-05 22:53:08 +00:00
|
|
|
const tableIndex = "index"
|
|
|
|
|
2021-02-05 22:45:27 +00:00
|
|
|
// indexTableSchema returns a new table schema used for tracking various the
|
|
|
|
// latest raft index for a table or entities within a table.
|
|
|
|
//
|
|
|
|
// The index table is necessary for tables that do not use tombstones. If the latest
|
|
|
|
// items in the table are deleted, the max index of a table would appear to go
|
|
|
|
// backwards. With the index table we can keep track of the latest update to a
|
|
|
|
// table, even when that update is a delete of the most recent item.
|
2015-08-22 00:23:01 +00:00
|
|
|
func indexTableSchema() *memdb.TableSchema {
|
|
|
|
return &memdb.TableSchema{
|
2021-02-05 22:53:08 +00:00
|
|
|
Name: tableIndex,
|
2015-08-22 00:23:01 +00:00
|
|
|
Indexes: map[string]*memdb.IndexSchema{
|
2021-02-05 22:53:08 +00:00
|
|
|
indexID: {
|
|
|
|
Name: indexID,
|
2015-08-22 00:23:01 +00:00
|
|
|
AllowMissing: false,
|
|
|
|
Unique: true,
|
|
|
|
Indexer: &memdb.StringFieldIndex{
|
|
|
|
Field: "Key",
|
|
|
|
Lowercase: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|