swarm/storage: godoc and comments

This commit is contained in:
Anton Evangelatov 2018-10-03 11:21:12 +02:00
parent c9cdc5edcf
commit 7f973b9cae
2 changed files with 4 additions and 0 deletions

View file

@ -731,6 +731,7 @@ func (s *LDBStore) tryAccessIdx(ikey []byte, index *dpaDBIndex) bool {
return true return true
} }
// GetSchema is returning the current named schema of the datastore as read from LevelDB
func (s *LDBStore) GetSchema() (string, error) { func (s *LDBStore) GetSchema() (string, error) {
s.lock.Lock() s.lock.Lock()
defer s.lock.Unlock() defer s.lock.Unlock()
@ -746,6 +747,7 @@ func (s *LDBStore) GetSchema() (string, error) {
return string(data), nil return string(data), nil
} }
// PutSchema is saving a named schema to the LevelDB datastore
func (s *LDBStore) PutSchema(schema string) error { func (s *LDBStore) PutSchema(schema string) error {
s.lock.Lock() s.lock.Lock()
defer s.lock.Unlock() defer s.lock.Unlock()

View file

@ -185,6 +185,7 @@ func (ls *LocalStore) Close() {
ls.DbStore.Close() ls.DbStore.Close()
} }
// Migrate checks the datastore schema vs the runtime schema, and runs migrations if they don't match
func (ls *LocalStore) Migrate() error { func (ls *LocalStore) Migrate() error {
schema, err := ls.DbStore.GetSchema() schema, err := ls.DbStore.GetSchema()
if err != nil { if err != nil {
@ -200,6 +201,7 @@ func (ls *LocalStore) Migrate() error {
log.Debug("running migrations for", "schema", schema, "runtime-schema", CurrentDbSchema) log.Debug("running migrations for", "schema", schema, "runtime-schema", CurrentDbSchema)
cleanupFunc := func(c *chunk) bool { cleanupFunc := func(c *chunk) bool {
// if one of the ls.Validators passes, it means a chunk is of particular type and it is valid
valid := false valid := false
for _, v := range ls.Validators { for _, v := range ls.Validators {
if valid = v.Validate(c.Address(), c.Data()); valid { if valid = v.Validate(c.Address(), c.Data()); valid {