Skip to content
Snippets Groups Projects
Select Git revision
  • df8e160b7c1c4b04422349192abb49d46c445617
  • without_tipselection default
  • develop protected
  • fix/grafana-local-dashboard
  • wasp
  • fix/dashboard-explorer-freeze
  • master
  • feat/timerqueue
  • test/sync_debug_and_650
  • feat/sync_revamp_inv
  • wip/sync
  • tool/db-recovery
  • portcheck/fix
  • fix/synchronization
  • feat/new-dashboard-analysis
  • feat/refactored-analysis-dashboard
  • feat/new-analysis-dashboard
  • test/demo-prometheus-fpc
  • prometheus_metrics
  • wip/analysis-server
  • merge/fpc-test-value-transfer
  • v0.2.2
  • v0.2.1
  • v0.2.0
  • v0.1.3
  • v0.1.2
  • v0.1.1
  • v0.1.0
28 results

main.go

Blame
  • health.go 1.15 KiB
    package database
    
    import (
    	"errors"
    	"fmt"
    
    	"github.com/iotaledger/goshimmer/packages/database/prefix"
    	"github.com/iotaledger/hive.go/kvstore"
    )
    
    var (
    	healthStore kvstore.KVStore
    	healthKey   = []byte("db_health")
    )
    
    func configureHealthStore(store kvstore.KVStore) {
    	healthStore = store.WithRealm([]byte{prefix.DBPrefixHealth})
    }
    
    // MarkDatabaseUnhealthy marks the database as not healthy, meaning
    // that it wasn't shutdown properly.
    func MarkDatabaseUnhealthy() {
    	if err := healthStore.Set(healthKey, []byte{}); err != nil {
    		panic(fmt.Errorf("failed to set database health state: %w", err))
    	}
    }
    
    // MarkDatabaseHealthy marks the database as healthy, respectively correctly closed.
    func MarkDatabaseHealthy() {
    	if err := healthStore.Delete(healthKey); err != nil && !errors.Is(err, kvstore.ErrKeyNotFound) {
    		panic(fmt.Errorf("failed to set database health state: %w", err))
    	}
    }
    
    // IsDatabaseUnhealthy tells whether the database is unhealthy, meaning not shutdown properly.
    func IsDatabaseUnhealthy() bool {
    	contains, err := healthStore.Has(healthKey)
    	if err != nil {
    		panic(fmt.Errorf("failed to set database health state: %w", err))
    	}
    	return contains
    }