當前位置: 首頁>>代碼示例>>Golang>>正文


Golang DBOverlay.InsertEntryMultiBatch方法代碼示例

本文整理匯總了Golang中github.com/FactomProject/factomd/common/interfaces.DBOverlay.InsertEntryMultiBatch方法的典型用法代碼示例。如果您正苦於以下問題:Golang DBOverlay.InsertEntryMultiBatch方法的具體用法?Golang DBOverlay.InsertEntryMultiBatch怎麽用?Golang DBOverlay.InsertEntryMultiBatch使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/FactomProject/factomd/common/interfaces.DBOverlay的用法示例。


在下文中一共展示了DBOverlay.InsertEntryMultiBatch方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: CopyDB

func CopyDB(dbase1, dbase2 interfaces.DBOverlay) {
	processing := ""
	defer func() {
		if r := recover(); r != nil {
			err := fmt.Errorf("Error processing: %v", processing)
			panic(err)
		}
	}()

	dBlocks, err := dbase1.FetchAllDBlocks()
	if err != nil {
		panic(err)
	}
	prevECHash := primitives.NewZeroHash()
	for _, dBlock := range dBlocks {
		dbase2.StartMultiBatch()

		err := dbase2.ProcessDBlockMultiBatch(dBlock)
		if err != nil {
			panic(err)
		}

		for _, dbEntry := range dBlock.GetDBEntries() {
			switch dbEntry.GetChainID().String() {
			case "000000000000000000000000000000000000000000000000000000000000000a":
				aBlock, err := dbase1.FetchABlock(dbEntry.GetKeyMR())
				if err != nil {
					panic(err)
				}
				err = dbase2.ProcessABlockMultiBatch(aBlock)
				if err != nil {
					panic(err)
				}
				break
			case "000000000000000000000000000000000000000000000000000000000000000c":
				ecBlock, err := dbase1.FetchECBlock(dbEntry.GetKeyMR())
				if err != nil {
					panic(err)
				}

				if ecBlock.GetHeader().GetPrevHeaderHash().IsSameAs(prevECHash) == false {
					prev, err := dbase1.FetchECBlock(ecBlock.GetHeader().GetPrevHeaderHash())
					if err != nil {
						panic(err)
					}
					err = dbase2.ProcessECBlockMultiBatch(prev, true)
					if err != nil {
						panic(err)
					}
				}

				err = dbase2.ProcessECBlockMultiBatch(ecBlock, true)
				if err != nil {
					panic(err)
				}
				prevECHash = dbEntry.GetKeyMR()
				break
			case "000000000000000000000000000000000000000000000000000000000000000f":
				fBlock, err := dbase1.FetchFBlock(dbEntry.GetKeyMR())
				if err != nil {
					panic(err)
				}
				err = dbase2.ProcessFBlockMultiBatch(fBlock)
				if err != nil {
					panic(err)
				}
				break
			default:
				processing = fmt.Sprintf("%v - %v - %v", dBlock.GetKeyMR().String(), dbEntry.GetChainID().String(), dbEntry.GetKeyMR().String())
				eBlock, err := dbase1.FetchEBlock(dbEntry.GetKeyMR())
				if err != nil {
					panic(err)
				}
				err = dbase2.ProcessEBlockMultiBatch(eBlock, true)
				if err != nil {
					panic(err)
				}
				for _, h := range eBlock.GetEntryHashes() {
					entry, err := dbase1.FetchEntry(h)
					if err != nil {
						panic(err)
					}
					err = dbase2.InsertEntryMultiBatch(entry)
					if err != nil {
						panic(err)
					}
				}
				break
			}
		}
		if err := dbase2.ExecuteMultiBatch(); err != nil {
			panic(err)
		}
		if dBlock.GetDatabaseHeight()%1000 == 0 {
			fmt.Printf("Processed block #%v\n", dBlock.GetDatabaseHeight())
		}
	}
}
開發者ID:FactomProject,項目名稱:factomd,代碼行數:98,代碼來源:DBCleanCopy.go


注:本文中的github.com/FactomProject/factomd/common/interfaces.DBOverlay.InsertEntryMultiBatch方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。