Пример #1
0
func main() {
	fmt.Println("Usage:")
	fmt.Println("DBCleanCopy level/bolt DBFileLocation")
	fmt.Println("Database will be copied over block by block to remove some DB inconsistencies")

	if len(os.Args) < 3 {
		fmt.Println("\nNot enough arguments passed")
		os.Exit(1)
	}
	if len(os.Args) > 3 {
		fmt.Println("\nToo many arguments passed")
		os.Exit(1)
	}

	levelBolt := os.Args[1]

	if levelBolt != level && levelBolt != bolt {
		fmt.Println("\nFirst argument should be `level` or `bolt`")
		os.Exit(1)
	}
	path := os.Args[2]

	var dbase1 *hybridDB.HybridDB
	var dbase2 *hybridDB.HybridDB

	var err error
	if levelBolt == bolt {
		dbase1 = hybridDB.NewBoltMapHybridDB(nil, path)
		dbase2 = hybridDB.NewBoltMapHybridDB(nil, "copied.db")
	} else {
		dbase1, err = hybridDB.NewLevelMapHybridDB(path, false)
		if err != nil {
			panic(err)
		}
		dbase2, err = hybridDB.NewLevelMapHybridDB("copied.db", true)
		if err != nil {
			panic(err)
		}
	}

	dbo1 := databaseOverlay.NewOverlay(dbase1)
	dbo2 := databaseOverlay.NewOverlay(dbase2)

	CopyDB(dbo1, dbo2)

	dbo1.Close()
	dbo2.Close()
}
Пример #2
0
func InitBolt(cfg *util.FactomdConfig) interfaces.DBOverlay {
	//fmt.Println("InitBolt")
	path := cfg.App.BoltDBPath + "/"

	os.MkdirAll(path, 0777)
	dbase := hybridDB.NewBoltMapHybridDB(nil, path+"FactomBolt-Import.db")
	return databaseOverlay.NewOverlay(dbase)
}
Пример #3
0
func (s *State) InitMapDB() error {
	if s.DB != nil {
		return nil
	}

	dbase := new(mapdb.MapDB)
	dbase.Init(nil)
	s.DB = databaseOverlay.NewOverlay(dbase)
	return nil
}
Пример #4
0
func (s *State) InitBoltDB() error {
	if s.DB != nil {
		return nil
	}

	cfg := s.Cfg.(*util.FactomdConfig)
	path := cfg.App.BoltDBPath + "/" + cfg.App.Network + "/"
	os.MkdirAll(path, 0777)
	dbase := hybridDB.NewBoltMapHybridDB(nil, path+"FactomBolt.db")
	s.DB = databaseOverlay.NewOverlay(dbase)
	return nil
}
func TestCheckDatabaseForLevelDB(t *testing.T) {
	m, err := leveldb.NewLevelDB(dbFilename, true)
	if err != nil {
		t.Errorf("%v", err)
	}
	defer CleanupLevelDB(t, m)

	dbo := databaseOverlay.NewOverlay(m)
	testHelper.PopulateTestDatabaseOverlay(dbo)

	CheckDatabase(dbo)

}
Пример #6
0
func InitLevelDB(cfg *util.FactomdConfig) interfaces.DBOverlay {
	//fmt.Println("InitLevelDB")
	path := cfg.App.LdbPath + "/" + "FactoidLevel-Import.db"

	dbase, err := hybridDB.NewLevelMapHybridDB(path, false)

	if err != nil || dbase == nil {
		dbase, err = hybridDB.NewLevelMapHybridDB(path, true)
		if err != nil {
			panic(err)
		}
	}

	return databaseOverlay.NewOverlay(dbase)
}
Пример #7
0
func (s *State) InitLevelDB() error {
	if s.DB != nil {
		return nil
	}

	cfg := s.Cfg.(*util.FactomdConfig)
	path := cfg.App.LdbPath + "/" + cfg.App.Network + "/" + "factoid_level.db"

	log.Printfln("Creating Database at %v", path)

	dbase, err := hybridDB.NewLevelMapHybridDB(path, false)

	if err != nil || dbase == nil {
		dbase, err = hybridDB.NewLevelMapHybridDB(path, true)
		if err != nil {
			return err
		}
	}

	s.DB = databaseOverlay.NewOverlay(dbase)
	return nil
}
Пример #8
0
func CreateEmptyTestDatabaseOverlay() *databaseOverlay.Overlay {
	return databaseOverlay.NewOverlay(new(mapdb.MapDB))
}
func CheckDatabase(db interfaces.IDatabase) {
	if db == nil {
		return
	}

	dbo := databaseOverlay.NewOverlay(db)

	dBlock, err := dbo.FetchDBlockHead()
	if err != nil {
		panic(err)
	}
	if dBlock == nil {
		panic("DBlock head not found")
	}

	next := FetchBlockSet(dbo, dBlock.DatabasePrimaryIndex())

	fmt.Printf("\tStarting consecutive block analysis\n")

	hashMap := map[string]string{}

	var i int
	for {
		/*
			if next.DBlock.GetDatabaseHeight()%1000 == 0 {
				fmt.Printf("\"%v\", //%v\n", next.DBlock.DatabasePrimaryIndex(), next.DBlock.GetDatabaseHeight())
			}
		*/
		prev := FetchBlockSet(dbo, next.DBlock.GetHeader().GetPrevKeyMR())

		hashMap[next.DBlock.DatabasePrimaryIndex().String()] = "OK"
		err = directoryBlock.CheckBlockPairIntegrity(next.DBlock, prev.DBlock)
		if err != nil {
			fmt.Printf("Error for DBlock %v %v - %v\n", next.DBlock.GetHeader().GetDBHeight(), next.DBlock.DatabasePrimaryIndex(), err)
		}

		hashMap[next.ABlock.DatabasePrimaryIndex().String()] = "OK"
		err = adminBlock.CheckBlockPairIntegrity(next.ABlock, prev.ABlock)
		if err != nil {
			fmt.Printf("Error for ABlock %v %v - %v\n", next.ABlock.GetDatabaseHeight(), next.ABlock.DatabasePrimaryIndex(), err)
		}

		hashMap[next.ECBlock.DatabasePrimaryIndex().String()] = "OK"
		err = entryCreditBlock.CheckBlockPairIntegrity(next.ECBlock, prev.ECBlock)
		if err != nil {
			fmt.Printf("Error for ECBlock %v %v - %v\n", next.ECBlock.GetDatabaseHeight(), next.ECBlock.DatabasePrimaryIndex(), err)
		}

		hashMap[next.FBlock.DatabasePrimaryIndex().String()] = "OK"
		err = factoid.CheckBlockPairIntegrity(next.FBlock, prev.FBlock)
		if err != nil {
			fmt.Printf("Error for FBlock %v %v - %v\n", next.FBlock.GetDatabaseHeight(), next.FBlock.DatabasePrimaryIndex(), err)
		}

		i++
		if prev.DBlock == nil {
			break
		}
		next = prev
	}

	fmt.Printf("\tFinished analysing %v sets of blocks\n", i)

	fmt.Printf("\tLooking for free-floating blocks\n")

	dBlocks, err := dbo.FetchAllDBlockKeys()
	if err != nil {
		panic(err)
	}
	if len(dBlocks) != i {
		fmt.Printf("Found %v dBlocks, expected %v\n", len(dBlocks), i)
	}
	for _, block := range dBlocks {
		if hashMap[block.String()] == "" {
			fmt.Printf("Free-floating DBlock - %v\n", block.String())
		}
	}

	aBlocks, err := dbo.FetchAllABlockKeys()
	if err != nil {
		panic(err)
	}
	if len(aBlocks) != i {
		fmt.Printf("Found %v aBlocks, expected %v\n", len(aBlocks), i)
	}
	for _, block := range aBlocks {
		if hashMap[block.String()] == "" {
			fmt.Printf("Free-floating ABlock - %v\n", block.String())
		}
	}

	fBlocks, err := dbo.FetchAllFBlockKeys()
	if err != nil {
		panic(err)
	}
	if len(fBlocks) != i {
		fmt.Printf("Found %v fBlocks, expected %v\n", len(fBlocks), i)
	}
	for _, block := range fBlocks {
		if hashMap[block.String()] == "" {
			fmt.Printf("Free-floating FBlock - %v\n", block.String())
		}
	}

	ecBlocks, err := dbo.FetchAllECBlockKeys()
	if err != nil {
		panic(err)
	}
	if len(ecBlocks) != i {
		fmt.Printf("Found %v ecBlocks, expected %v\n", len(ecBlocks), i)
	}
	for _, block := range ecBlocks {
		if hashMap[block.String()] == "" {
			fmt.Printf("Free-floating ECBlock - %v\n", block.String())
		}
	}

	fmt.Printf("\tFinished looking for free-floating blocks\n")
}
Пример #10
0
func InitMapDB(cfg *util.FactomdConfig) interfaces.DBOverlay {
	//fmt.Println("InitMapDB")
	dbase := new(mapdb.MapDB)
	dbase.Init(nil)
	return databaseOverlay.NewOverlay(dbase)
}
Пример #11
0
func (s *State) SetDB(dbase interfaces.DBOverlay) {
	s.DB = databaseOverlay.NewOverlay(dbase)
}