One suggestion to the fuction named createLedgerID


Manish
 

To correct my previous reply - Dave reminded me of what we wanted to achieve here and the purpose of passing the block in this function at the first place.
So, this is a bug and thanks Dave for opening the Jira for this - https://jira.hyperledger.org/browse/FAB-10141

On Wed, May 16, 2018 at 1:00 PM, Manish <manish.sethi@...> wrote:
Somehow, hit the ‘reply’ instead of reply all...

---------- Forwarded message ----------
From: Manish Sethi <manish.sethi@...>
Date: Wed, May 16, 2018 at 11:56 AM
Subject: Re: [Hyperledger Fabric] One suggestion to the fuction named createLedgerID
To: wangzp <wangzhipengxlj@...>


Yes, it can be be dropped. As you see that this parameter is not used in this function as such.

Thanks,
Manish

On Wed, May 16, 2018 at 11:37 AM, wangzp <wangzhipengxlj@...> wrote:
If you are right,  gb can be removed.





发自OPPO邮件客户端
在 Manish Sethi <manish.sethi@...>,2018年5月16日 21:05写道:

Before putting a `nil` value, block is already written to the block storage. It can survive a crash after that.
Even if we add the genesis block to the leveldb, a crash can happen before, in the middle, or after writting it to the db.
It does not reduce the amount of work that needs to be performed for maintaining it a crash-consistent.


On Wed, May 16, 2018 at 4:06 AM, ??? <wangzhipengxlj@...> wrote:
func (s *idStore) createLedgerID(ledgerID string, gb *common.Block) error {
key := s.encodeLedgerKey(ledgerID)
var val []byte
var err error
if val, err = proto.Marshal(gb); err != nil {
return err
}
if val, err = s.db.Get(key); err != nil {
return err
}
if val != nil {
return ErrLedgerIDExists
}
batch := &leveldb.Batch{}
batch.Put(key, val)
batch.Delete(underConstructionLedgerKey)
return s.db.WriteBatch(batch, true)
}

func (s *idStore) ledgerIDExists(ledgerID string) (bool, error) {
key := s.encodeLedgerKey(ledgerID)
val := []byte{}
err := error(nil)
if val, err = s.db.Get(key); err != nil {
return false, err
}
return val != nil, nil
}

Two functions in `core/ledger/kvledger/kv_ledger_provider.go` in version v1.10;
 In `createLedgerID()`, put `nil` value with the key of `ledgerID` into the `ledgerProviderDB` . Why not put the genesis block into the `ledgerProviderDB` ?  When a crash occurs, the ledger can still be generated with the genesis block after restart.


 






Manish
 

Somehow, hit the ‘reply’ instead of reply all...

---------- Forwarded message ----------
From: Manish Sethi <manish.sethi@...>
Date: Wed, May 16, 2018 at 11:56 AM
Subject: Re: [Hyperledger Fabric] One suggestion to the fuction named createLedgerID
To: wangzp <wangzhipengxlj@...>


Yes, it can be be dropped. As you see that this parameter is not used in this function as such.

Thanks,
Manish

On Wed, May 16, 2018 at 11:37 AM, wangzp <wangzhipengxlj@...> wrote:
If you are right,  gb can be removed.





发自OPPO邮件客户端
在 Manish Sethi <manish.sethi@...>,2018年5月16日 21:05写道:

Before putting a `nil` value, block is already written to the block storage. It can survive a crash after that.
Even if we add the genesis block to the leveldb, a crash can happen before, in the middle, or after writting it to the db.
It does not reduce the amount of work that needs to be performed for maintaining it a crash-consistent.


On Wed, May 16, 2018 at 4:06 AM, ??? <wangzhipengxlj@...> wrote:
func (s *idStore) createLedgerID(ledgerID string, gb *common.Block) error {
key := s.encodeLedgerKey(ledgerID)
var val []byte
var err error
if val, err = proto.Marshal(gb); err != nil {
return err
}
if val, err = s.db.Get(key); err != nil {
return err
}
if val != nil {
return ErrLedgerIDExists
}
batch := &leveldb.Batch{}
batch.Put(key, val)
batch.Delete(underConstructionLedgerKey)
return s.db.WriteBatch(batch, true)
}

func (s *idStore) ledgerIDExists(ledgerID string) (bool, error) {
key := s.encodeLedgerKey(ledgerID)
val := []byte{}
err := error(nil)
if val, err = s.db.Get(key); err != nil {
return false, err
}
return val != nil, nil
}

Two functions in `core/ledger/kvledger/kv_ledger_provider.go` in version v1.10;
 In `createLedgerID()`, put `nil` value with the key of `ledgerID` into the `ledgerProviderDB` . Why not put the genesis block into the `ledgerProviderDB` ?  When a crash occurs, the ledger can still be generated with the genesis block after restart.


 





??? <wangzhipengxlj@...>
 

func (s *idStore) createLedgerID(ledgerID string, gb *common.Block) error {
key := s.encodeLedgerKey(ledgerID)
var val []byte
var err error
if val, err = proto.Marshal(gb); err != nil {
return err
}
if val, err = s.db.Get(key); err != nil {
return err
}
if val != nil {
return ErrLedgerIDExists
}
batch := &leveldb.Batch{}
batch.Put(key, val)
batch.Delete(underConstructionLedgerKey)
return s.db.WriteBatch(batch, true)
}

func (s *idStore) ledgerIDExists(ledgerID string) (bool, error) {
key := s.encodeLedgerKey(ledgerID)
val := []byte{}
err := error(nil)
if val, err = s.db.Get(key); err != nil {
return false, err
}
return val != nil, nil
}

Two functions in `core/ledger/kvledger/kv_ledger_provider.go` in version v1.10;
 In `createLedgerID()`, put `nil` value with the key of `ledgerID` into the `ledgerProviderDB` . Why not put the genesis block into the `ledgerProviderDB` ?  When a crash occurs, the ledger can still be generated with the genesis block after restart.