Skip to content
Snippets Groups Projects
Select Git revision
  • 9351e3648306b3229bbb44446c825da7a0e0abb2
  • develop default protected
  • congestioncontrol
  • merge-v-data-collection-spammer-0.8.2
  • WIP-merge-v-data-collection-spammer-0.8.2
  • merge-v-data-collection-spammer-0.7.7
  • tmp
  • test-masterpow-fixing
  • test-masterpow
  • test-echo
  • v-data-collection
  • v-data-collection-spammer
  • tmp-dump-spam-info
  • dump-msg-info-0.3.1
  • test-dump-message-info
  • spammer-exprandom
  • extra/tutorial
  • without_tipselection
  • hacking-docker-network
  • hacking-docker-network-0.2.3
  • master
  • v0.2.3
22 results

README.md

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
    }