mirror of
https://github.com/optim-enterprises-bv/vault.git
synced 2025-11-02 03:27:54 +00:00
Adds replication state helper to framework.Backend (#21743)
* Adds replication state helper to framework.Backend * Fix test * adds changelog
This commit is contained in:
@@ -60,6 +60,11 @@ type Backend struct {
|
||||
|
||||
// InitializeFunc is the callback, which if set, will be invoked via
|
||||
// Initialize() just after a plugin has been mounted.
|
||||
//
|
||||
// Note that storage writes should only occur on the active instance within a
|
||||
// primary cluster or local mount on a performance secondary. If your InitializeFunc
|
||||
// writes to storage, you can use the backend's WriteSafeReplicationState() method
|
||||
// to prevent it from attempting to write on a Vault instance with read-only storage.
|
||||
InitializeFunc InitializeFunc
|
||||
|
||||
// PeriodicFunc is the callback, which if set, will be invoked when the
|
||||
@@ -70,6 +75,11 @@ type Backend struct {
|
||||
// entries in backend's storage, while the backend is still being used.
|
||||
// (Note the difference between this action and `Clean`, which is
|
||||
// invoked just before the backend is unmounted).
|
||||
//
|
||||
// Note that storage writes should only occur on the active instance within a
|
||||
// primary cluster or local mount on a performance secondary. If your PeriodicFunc
|
||||
// writes to storage, you can use the backend's WriteSafeReplicationState() method
|
||||
// to prevent it from attempting to write on a Vault instance with read-only storage.
|
||||
PeriodicFunc periodicFunc
|
||||
|
||||
// WALRollback is called when a WAL entry (see wal.go) has to be rolled
|
||||
@@ -466,6 +476,16 @@ func (b *Backend) Secret(k string) *Secret {
|
||||
return nil
|
||||
}
|
||||
|
||||
// WriteSafeReplicationState returns true if this backend instance is capable of writing
|
||||
// to storage without receiving an ErrReadOnly error. The active instance in a primary
|
||||
// cluster or a local mount on a performance secondary is capable of writing to storage.
|
||||
func (b *Backend) WriteSafeReplicationState() bool {
|
||||
replicationState := b.System().ReplicationState()
|
||||
return (b.System().LocalMount() || !replicationState.HasState(consts.ReplicationPerformanceSecondary)) &&
|
||||
!replicationState.HasState(consts.ReplicationDRSecondary) &&
|
||||
!replicationState.HasState(consts.ReplicationPerformanceStandby)
|
||||
}
|
||||
|
||||
func (b *Backend) init() {
|
||||
b.pathsRe = make([]*regexp.Regexp, len(b.Paths))
|
||||
for i, p := range b.Paths {
|
||||
|
||||
Reference in New Issue
Block a user