Skip to content
This repository has been archived by the owner on Jul 6, 2022. It is now read-only.

Commit

Permalink
try opt mem use
Browse files Browse the repository at this point in the history
  • Loading branch information
af913337456 committed Oct 20, 2021
1 parent 7497b1c commit a65995c
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 11 deletions.
2 changes: 1 addition & 1 deletion api/local_handler.go
Expand Up @@ -73,7 +73,7 @@ func (r *RpcLocalHandler) GetAddressAccount(address string) common.ReqResp {
} else if jsonArrBys == nil {
return common.ReqResp{ErrNo: dascode.Err_AccountNotExist, ErrMsg: "account not exist, it may not be stored in the local database yet"}
}
accountList, err := types.AccountReturnObjListFromBys(jsonArrBys)
accountList, err := types.AccountReturnObjListFromBys(&jsonArrBys)
if err != nil {
return common.ReqResp{ErrNo: dascode.Err_Internal, ErrMsg: fmt.Errorf("AccountReturnObjListFromBys err: %s", err.Error()).Error()}
}
Expand Down
Binary file modified bin/mac/rpc_server
Binary file not shown.
17 changes: 10 additions & 7 deletions parser/handler/common.go
Expand Up @@ -6,7 +6,6 @@ import (
"fmt"
"github.com/DeAccountSystems/das_commonlib/common/rocksdb"
"github.com/tecbot/gorocksdb"
"runtime"
)

/**
Expand Down Expand Up @@ -37,7 +36,7 @@ func removeItemFromOwnerList(db *gorocksdb.DB, writeBatch *gorocksdb.WriteBatch,
if err != nil {
return fmt.Errorf("RocksDbSafeGet err: %s", err.Error())
} else if jsonArrBys != nil {
oldList, err := types.AccountReturnObjListFromBys(jsonArrBys)
oldList, err := types.AccountReturnObjListFromBys(&jsonArrBys)
if err != nil {
return fmt.Errorf("AccountReturnObjListFromBys err: %s", err.Error())
}
Expand All @@ -58,13 +57,16 @@ func removeItemFromOwnerList(db *gorocksdb.DB, writeBatch *gorocksdb.WriteBatch,
// func storeAccountInfoToRocksDb(db *gorocksdb.DB, writeBatch *gorocksdb.WriteBatch, accountList types.AccountReturnObjList) (int, error) {
// accountSize := len(accountList)
// sameOwnerMap := map[string]types.AccountReturnObjList{}
// accountIdOwnerMap := map[string]string{}
// // make group and replace the AccountKey_AccountId data
// for i := 0; i < accountSize; i++ {
// item := accountList[i]
// jsonBys := item.JsonBys()
// writeBatch.Put(AccountKey_AccountId(item.AccountData.AccountId()), jsonBys)
// accountId := item.AccountData.AccountId()
// writeBatch.Put(AccountKey_AccountId(accountId), jsonBys)
// ownerLockArgsKey := AccountKey_OwnerArgHex(item.AccountData.OwnerLockArgsHex)
// ownerHexKey := hex.EncodeToString(ownerLockArgsKey)
// accountIdOwnerMap[accountId.Str()] = ownerHexKey
// if preList := sameOwnerMap[ownerHexKey]; len(preList) > 0 {
// preList = append(preList, item)
// sameOwnerMap[ownerHexKey] = preList
Expand Down Expand Up @@ -104,10 +106,12 @@ func removeItemFromOwnerList(db *gorocksdb.DB, writeBatch *gorocksdb.WriteBatch,
// // genesis account storage
// storeItem = newItem
// delete(ownerListMap, mapKey)
// } else {
// } else if accountIdOwnerMap[storeItem.AccountData.AccountId().Str()] == ownerHexKey {
// // not exist, keep the old record
// } else {
// continue // this account has change owner
// }
// newList = append(newList, storeItem)
// newList = append(newList, storeItem) // here
// }
// for _, absNewItem := range ownerListMap {
// newList = append(newList, absNewItem)
Expand Down Expand Up @@ -151,7 +155,7 @@ func storeAccountInfoToRocksDb(db *gorocksdb.DB, writeBatch *gorocksdb.WriteBatc
dbList = append(dbList, item)
putsItem(ownerLockArgsHexKey, &item, &dbList)
} else {
oldList, err := types.AccountReturnObjListFromBys(jsonArrBys)
oldList, err := types.AccountReturnObjListFromBys(&jsonArrBys)
if err != nil {
return 0, fmt.Errorf("AccountReturnObjListFromBys err: %s", err.Error())
}
Expand All @@ -166,7 +170,6 @@ func storeAccountInfoToRocksDb(db *gorocksdb.DB, writeBatch *gorocksdb.WriteBatc
log.Info(fmt.Sprintf(
"storeAccountInfoToRocksDb, add new item, account: %s, id: %s, owner: %s",
item.AccountData.Account, item.AccountData.AccountIdHex, item.AccountData.OwnerLockArgsHex))
runtime.Gosched()
putsItem(ownerLockArgsHexKey, &item, &newList)
}
}
Expand Down
2 changes: 1 addition & 1 deletion parser/handler/handler_test.go
Expand Up @@ -127,7 +127,7 @@ func getAddressAccount(address string, rocksdb *gorocksdb.DB) common.ReqResp {
} else if jsonArrBys == nil {
return common.ReqResp{ErrNo: dascode.Err_AccountNotExist, ErrMsg: "account not exist, it may not be stored in the local database yet"}
}
accountList, err := types.AccountReturnObjListFromBys(jsonArrBys)
accountList, err := types.AccountReturnObjListFromBys(&jsonArrBys)
if err != nil {
return common.ReqResp{ErrNo: dascode.Err_Internal, ErrMsg: fmt.Errorf("AccountReturnObjListFromBys err: %s", err.Error()).Error()}
}
Expand Down
4 changes: 2 additions & 2 deletions types/account.go
Expand Up @@ -170,9 +170,9 @@ func (a AccountReturnObjList) ToAccountReturnObjList1List(testNet bool) []Accoun
return retList
}

func AccountReturnObjListFromBys(listBys []byte) (AccountReturnObjList, error) {
func AccountReturnObjListFromBys(listBys *[]byte) (AccountReturnObjList, error) {
list := &AccountReturnObjList{}
if err := json.Unmarshal(listBys, list); err != nil {
if err := json.Unmarshal(*listBys, list); err != nil {
return nil, err
}
return *list, nil
Expand Down

0 comments on commit a65995c

Please sign in to comment.