Beispiel #1
0
func LoadDatabase(s *State) {
	defer SetDBFinished(s)

	var blkCnt uint32

	head, err := s.DB.FetchDirectoryBlockHead()
	if err == nil && head != nil {
		blkCnt = head.GetHeader().GetDBHeight()
	}

	t := time.Now()

	//msg, err := s.LoadDBState(blkCnt)

	for i := 0; true; i++ {
		if i > 0 && i%1000 == 0 {
			since := time.Since(t)
			ss := float64(since.Nanoseconds()) / 1000000000
			bps := float64(i) / ss
			os.Stderr.WriteString(fmt.Sprintf("%20s Loading Block %7d / %v. Blocks per second %8.2f\n", s.FactomNodeName, i, blkCnt, bps))
		}
		msg, err := s.LoadDBState(uint32(i))
		if err != nil {
			s.Println(err.Error())
			os.Stderr.WriteString(fmt.Sprintf("%20s Error reading database at block %d: %s\n", s.FactomNodeName, i, err.Error()))
			break
		} else {
			if msg != nil {
				s.InMsgQueue() <- msg
				msg.SetLocal(true)
				if len(s.InMsgQueue()) > 20 {
					for len(s.InMsgQueue()) > 10 {
						time.Sleep(10 * time.Millisecond)
					}
				}
			} else {
				// os.Stderr.WriteString(fmt.Sprintf("%20s Last Block in database: %d\n", s.FactomNodeName, i))
				break
			}
		}

		s.Print("\r", "\\|/-"[i%4:i%4+1])
	}

	if blkCnt == 0 {
		s.Println("\n***********************************")
		s.Println("******* New Database **************")
		s.Println("***********************************\n")

		dblk, ablk, fblk, ecblk := GenerateGenesisBlocks(s.GetNetworkID())

		msg := messages.NewDBStateMsg(s.GetTimestamp(), dblk, ablk, fblk, ecblk, nil, nil)
		s.InMsgQueue() <- msg
	}
	s.Println(fmt.Sprintf("Loaded %d directory blocks on %s", blkCnt, s.FactomNodeName))
}
Beispiel #2
0
func CreateTestDBStateList() []interfaces.IMsg {
	answer := make([]interfaces.IMsg, BlockCount)
	var prev *BlockSet = nil

	for i := 0; i < BlockCount; i++ {
		prev = CreateTestBlockSet(prev)

		timestamp := primitives.NewTimestampNow()
		timestamp.SetTime(uint64(i * 1000 * 60 * 60 * 6)) //6 hours of difference between messages

		answer[i] = messages.NewDBStateMsg(timestamp, prev.DBlock, prev.ABlock, prev.FBlock, prev.ECBlock, nil, nil)
	}
	return answer
}