Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Leveldb #322

Merged
merged 27 commits into from Dec 17, 2018
Merged

Leveldb #322

merged 27 commits into from Dec 17, 2018

Conversation

almogdepaz
Copy link
Contributor

add level db to our mesh for persistence

db.db.Close()
}

func (db LevelDB) Put(key, value []byte) error {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in my opnion receiver should be of pointer type

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LevelDB holds only pointers

defer m.lMutex.Unlock()
count := LayerID(m.LatestIrreversible())
if count > layer.Index() {
log.Debug("can't add layer ", layer.Index(), "(already exists)")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what if layers are not ordered?

func (m *mesh) SetLatestKnownLayer(idx uint32) {
defer m.lkMutex.Unlock()
m.lkMutex.Lock()
if idx > m.latestKnownLayer {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

using atomic here will simplify code as well

return err
}
m.SetLatestKnownLayer(uint32(block.Layer()))
m.tortoise.HandleLateBlock(block) //todo should be thread safe?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, but lets discuss this


func (m *mesh) Close() {
log.Debug("closing mDB")
m.mDB.Close()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we keep a closed flag? otherwise what are the consequences of closing?

mesh/meshdb.go Outdated
bytes, err := blockAsBytes(*b)
if err != nil {
log.Error("problem serializing block ", b.ID(), err)
delete(ids, b.ID()) //remove failed block from layer
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This error is critical and should not be supressed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i don't think we should stop adding the whole layer because of a failed block

mesh/meshdb.go Outdated

err = m.blocks.Put(b.ID().ToBytes(), bytes)
if err != nil {
log.Error("could not add block ", b.ID(), " to database ", err)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

mesh/meshdb.go Outdated
layerLock, found := m.layerLocks[index]
if !found {
layerLock = sync.Mutex{}
m.layerLocks[index] = layerLock
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

leak - there is no mechanism for removing unused locks

sync/sync.go Outdated
@@ -198,7 +202,7 @@ func (s *Syncer) getLayerBlockIDs(index uint32) chan uint32 {
m[string(hash)] = p
}

idSet := make(map[uint32]bool, 300) //todo move this to config
idSet := make(map[uint64]bool, 300) //todo move this to config
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please move to config or at least name it

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unnamed and not labeled because this goes to protobuff serialisation right now and protobuff dosent handle that very well

sync/sync.go Outdated
@@ -213,24 +217,28 @@ func (s *Syncer) getLayerBlockIDs(index uint32) chan uint32 {
}
}

res := make(chan uint32, len(idSet))
res := make(chan mesh.BlockID, len(idSet))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typedef chan if using it as a queue

@almogdepaz almogdepaz merged commit 5912efb into develop Dec 17, 2018
@y0sher y0sher deleted the leveldb branch June 25, 2019 07:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants