ACL Binding Rules table partitioning (#11044)
* ACL Binding Rules table partitioning Signed-off-by: Mark Anderson <manderson@hashicorp.com>
This commit is contained in:
parent
6ae4d7bb70
commit
08b222cfc3
|
@ -48,7 +48,7 @@ func (s *Restore) ACLRole(role *structs.ACLRole) error {
|
||||||
|
|
||||||
// ACLBindingRules is used when saving a snapshot
|
// ACLBindingRules is used when saving a snapshot
|
||||||
func (s *Snapshot) ACLBindingRules() (memdb.ResultIterator, error) {
|
func (s *Snapshot) ACLBindingRules() (memdb.ResultIterator, error) {
|
||||||
iter, err := s.tx.Get(tableACLBindingRules, "id")
|
iter, err := s.tx.Get(tableACLBindingRules, indexID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -180,11 +180,11 @@ func aclBindingRuleInsert(tx WriteTxn, rule *structs.ACLBindingRule) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func aclBindingRuleGetByID(tx ReadTxn, id string, _ *structs.EnterpriseMeta) (<-chan struct{}, interface{}, error) {
|
func aclBindingRuleGetByID(tx ReadTxn, id string, _ *structs.EnterpriseMeta) (<-chan struct{}, interface{}, error) {
|
||||||
return tx.FirstWatch(tableACLBindingRules, "id", id)
|
return tx.FirstWatch(tableACLBindingRules, indexID, id)
|
||||||
}
|
}
|
||||||
|
|
||||||
func aclBindingRuleList(tx ReadTxn, _ *structs.EnterpriseMeta) (memdb.ResultIterator, error) {
|
func aclBindingRuleList(tx ReadTxn, _ *structs.EnterpriseMeta) (memdb.ResultIterator, error) {
|
||||||
return tx.Get(tableACLBindingRules, "id")
|
return tx.Get(tableACLBindingRules, indexID)
|
||||||
}
|
}
|
||||||
|
|
||||||
func aclBindingRuleListByAuthMethod(tx ReadTxn, method string, _ *structs.EnterpriseMeta) (memdb.ResultIterator, error) {
|
func aclBindingRuleListByAuthMethod(tx ReadTxn, method string, _ *structs.EnterpriseMeta) (memdb.ResultIterator, error) {
|
||||||
|
|
|
@ -147,7 +147,19 @@ func testIndexerTableACLBindingRules() map[string]indexerTestCase {
|
||||||
ID: "123e4567-e89a-12d7-a456-426614174abc",
|
ID: "123e4567-e89a-12d7-a456-426614174abc",
|
||||||
AuthMethod: "BinDingRuLe",
|
AuthMethod: "BinDingRuLe",
|
||||||
}
|
}
|
||||||
|
encodedID := []byte{0x12, 0x3e, 0x45, 0x67, 0xe8, 0x9a, 0x12, 0xd7, 0xa4, 0x56, 0x42, 0x66, 0x14, 0x17, 0x4a, 0xbc}
|
||||||
|
|
||||||
return map[string]indexerTestCase{
|
return map[string]indexerTestCase{
|
||||||
|
indexID: {
|
||||||
|
read: indexValue{
|
||||||
|
source: obj.ID,
|
||||||
|
expected: encodedID,
|
||||||
|
},
|
||||||
|
write: indexValue{
|
||||||
|
source: obj,
|
||||||
|
expected: encodedID,
|
||||||
|
},
|
||||||
|
},
|
||||||
indexAuthMethod: {
|
indexAuthMethod: {
|
||||||
read: indexValue{
|
read: indexValue{
|
||||||
source: Query{Value: "BinDingRuLe"},
|
source: Query{Value: "BinDingRuLe"},
|
||||||
|
|
|
@ -268,8 +268,9 @@ func bindingRulesTableSchema() *memdb.TableSchema {
|
||||||
Name: indexID,
|
Name: indexID,
|
||||||
AllowMissing: false,
|
AllowMissing: false,
|
||||||
Unique: true,
|
Unique: true,
|
||||||
Indexer: &memdb.UUIDFieldIndex{
|
Indexer: indexerSingle{
|
||||||
Field: "ID",
|
readIndex: readIndex(indexFromUUIDString),
|
||||||
|
writeIndex: writeIndex(indexIDFromACLBindingRule),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
indexAuthMethod: {
|
indexAuthMethod: {
|
||||||
|
@ -285,6 +286,19 @@ func bindingRulesTableSchema() *memdb.TableSchema {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func indexIDFromACLBindingRule(raw interface{}) ([]byte, error) {
|
||||||
|
p, ok := raw.(*structs.ACLBindingRule)
|
||||||
|
if !ok {
|
||||||
|
return nil, fmt.Errorf("unexpected type %T for structs.ACLBindingRule index", raw)
|
||||||
|
}
|
||||||
|
vv, err := uuidStringToBytes(p.ID)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return vv, err
|
||||||
|
}
|
||||||
|
|
||||||
func indexAuthMethodFromACLBindingRule(raw interface{}) ([]byte, error) {
|
func indexAuthMethodFromACLBindingRule(raw interface{}) ([]byte, error) {
|
||||||
p, ok := raw.(*structs.ACLBindingRule)
|
p, ok := raw.(*structs.ACLBindingRule)
|
||||||
if !ok {
|
if !ok {
|
||||||
|
|
Loading…
Reference in New Issue