Skip to content
This repository was archived by the owner on Aug 2, 2021. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
58c84c9
swarm-rather-stable: Localstore storage integration (janos) + Localst…
nonsense Apr 10, 2019
e7f9daa
swarm/storage/localstore: fix export db.Put signature
nonsense Apr 11, 2019
7e9d668
cmd/swarm/swarm-smoke: improve smoke tests (#1337)
nonsense Apr 11, 2019
9a5bfef
swarm/network: remove dead code (#1339)
nonsense Apr 12, 2019
f107234
swarm/network: remove FetchStore and SyncChunkStore in favor of NetSt…
nonsense Apr 12, 2019
233ebce
Swarm rather stable: LocalStore metrics (#1349)
janos Apr 25, 2019
5f9a40d
p2p/protocols, swarm/network: fix resource leak with p2p teardown (#1…
acud Apr 26, 2019
d5c7f04
cmd/swarm-smoke: check if chunks are at most prox host (#1353)
nonsense Apr 26, 2019
7269715
swarm/network: measure how many chunks a node delivers (#1358)
nonsense Apr 29, 2019
be8d008
swarm/chunk: add tags data type (#1341)
acud Apr 30, 2019
09c7766
Swarm rather stable: update syncing (#1336)
janos Apr 30, 2019
bbdc269
swarm: push tags integration - request flow (#1347)
acud May 5, 2019
76a767a
swarm-smoke: add syncDelay flag (#1366)
nonsense May 6, 2019
a1906d0
swarm/network: add want delay timer to syncing (#1367)
nonsense May 6, 2019
ab7981c
swarm/network: synchronise peer.close() (#1369)
nonsense May 6, 2019
1e6dba5
swarm/pss: Disable failing handshake test (#1365)
nolash May 6, 2019
e20d6b3
swarm/storage: comment typo (#1370)
nonsense May 7, 2019
80119ab
swarm/storage/localstore: fix broken metric (#1373)
acud May 7, 2019
ddd1154
count different messages (#1374)
nonsense May 7, 2019
37d1b72
cmd/swarm: disable snapshot create test due to constant flakes (#1376)
acud May 7, 2019
2652eac
swarm/network: remove redundant goroutine (#1377)
nonsense May 8, 2019
a6e8dfd
swarm: instrument setNextBatch (#1381)
acud May 9, 2019
f1af80c
swarm/storage/localstore: add gc metrics, disable flaky test (#1384)
acud May 9, 2019
10eb423
swarm/network: measure addPeer and deletePeer to know if Kad rearrang…
nonsense May 9, 2019
42c0342
swarm/storage: remove traces for put/get/set (#1389)
nonsense May 9, 2019
c98771c
resolved conflict
nonsense May 10, 2019
848cac6
swarm/storage/localstore, swarm/chunk, swarm/shed: tag integration
zelig May 10, 2019
d22ca42
swarm/pss: add pubsub
zelig May 10, 2019
64406ed
swarm/storage/pushsync: push sync
zelig May 10, 2019
1ab4198
swarm: pushsync integration into swarm
zelig May 10, 2019
3b9feb6
remove later
nonsense May 10, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions cmd/swarm/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,15 +252,15 @@ func cmdLineOverride(currentConfig *bzzapi.Config, ctx *cli.Context) *bzzapi.Con
}

if storePath := ctx.GlobalString(SwarmStorePath.Name); storePath != "" {
currentConfig.LocalStoreParams.ChunkDbPath = storePath
currentConfig.ChunkDbPath = storePath
}

if storeCapacity := ctx.GlobalUint64(SwarmStoreCapacity.Name); storeCapacity != 0 {
currentConfig.LocalStoreParams.DbCapacity = storeCapacity
currentConfig.DbCapacity = storeCapacity
}

if ctx.GlobalIsSet(SwarmStoreCacheCapacity.Name) {
currentConfig.LocalStoreParams.CacheCapacity = ctx.GlobalUint(SwarmStoreCacheCapacity.Name)
currentConfig.CacheCapacity = ctx.GlobalUint(SwarmStoreCacheCapacity.Name)
}

if ctx.GlobalIsSet(SwarmBootnodeModeFlag.Name) {
Expand Down
4 changes: 2 additions & 2 deletions cmd/swarm/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -447,8 +447,8 @@ func TestConfigCmdLineOverridesFile(t *testing.T) {
t.Fatal("Expected Sync to be disabled, but is true")
}

if info.LocalStoreParams.DbCapacity != 9000000 {
t.Fatalf("Expected Capacity to be %d, got %d", 9000000, info.LocalStoreParams.DbCapacity)
if info.DbCapacity != 9000000 {
t.Fatalf("Expected Capacity to be %d, got %d", 9000000, info.DbCapacity)
}

if info.HiveParams.KeepAliveInterval != 6000000000 {
Expand Down
118 changes: 105 additions & 13 deletions cmd/swarm/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
package main

import (
"archive/tar"
"bytes"
"encoding/binary"
"encoding/hex"
"fmt"
"io"
"os"
Expand All @@ -25,10 +29,22 @@ import (
"github.com/ethereum/go-ethereum/cmd/utils"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/swarm/storage"
"github.com/ethereum/go-ethereum/rlp"
"github.com/ethereum/go-ethereum/swarm/chunk"
"github.com/ethereum/go-ethereum/swarm/storage/localstore"
"github.com/syndtr/goleveldb/leveldb"
"github.com/syndtr/goleveldb/leveldb/opt"
"gopkg.in/urfave/cli.v1"
)

var legacyKeyIndex = byte(0)
var keyData = byte(6)

type dpaDBIndex struct {
Idx uint64
Access uint64
}

var dbCommand = cli.Command{
Name: "db",
CustomHelpTemplate: helpTemplate,
Expand Down Expand Up @@ -67,6 +83,9 @@ The import may be quite large, consider piping the input through the Unix
pv(1) tool to get a progress bar:

pv chunks.tar | swarm db import ~/.ethereum/swarm/bzz-KEY/chunks -`,
Flags: []cli.Flag{
SwarmLegacyFlag,
},
},
},
}
Expand All @@ -77,12 +96,6 @@ func dbExport(ctx *cli.Context) {
utils.Fatalf("invalid arguments, please specify both <chunkdb> (path to a local chunk database), <file> (path to write the tar archive to, - for stdout) and the base key")
}

store, err := openLDBStore(args[0], common.Hex2Bytes(args[2]))
if err != nil {
utils.Fatalf("error opening local chunk database: %s", err)
}
defer store.Close()

var out io.Writer
if args[1] == "-" {
out = os.Stdout
Expand All @@ -95,6 +108,23 @@ func dbExport(ctx *cli.Context) {
out = f
}

isLegacy := localstore.IsLegacyDatabase(args[0])
if isLegacy {
count, err := exportLegacy(args[0], common.Hex2Bytes(args[2]), out)
if err != nil {
utils.Fatalf("error exporting legacy local chunk database: %s", err)
}

log.Info(fmt.Sprintf("successfully exported %d chunks from legacy db", count))
return
}

store, err := openLDBStore(args[0], common.Hex2Bytes(args[2]))
if err != nil {
utils.Fatalf("error opening local chunk database: %s", err)
}
defer store.Close()

count, err := store.Export(out)
if err != nil {
utils.Fatalf("error exporting local chunk database: %s", err)
Expand All @@ -109,6 +139,8 @@ func dbImport(ctx *cli.Context) {
utils.Fatalf("invalid arguments, please specify both <chunkdb> (path to a local chunk database), <file> (path to read the tar archive from, - for stdin) and the base key")
}

legacy := ctx.IsSet(SwarmLegacyFlag.Name)

store, err := openLDBStore(args[0], common.Hex2Bytes(args[2]))
if err != nil {
utils.Fatalf("error opening local chunk database: %s", err)
Expand All @@ -127,21 +159,81 @@ func dbImport(ctx *cli.Context) {
in = f
}

count, err := store.Import(in)
count, err := store.Import(in, legacy)
if err != nil {
utils.Fatalf("error importing local chunk database: %s", err)
}

log.Info(fmt.Sprintf("successfully imported %d chunks", count))
}

func openLDBStore(path string, basekey []byte) (*storage.LDBStore, error) {
func openLDBStore(path string, basekey []byte) (*localstore.DB, error) {
if _, err := os.Stat(filepath.Join(path, "CURRENT")); err != nil {
return nil, fmt.Errorf("invalid chunkdb path: %s", err)
}

storeparams := storage.NewDefaultStoreParams()
ldbparams := storage.NewLDBStoreParams(storeparams, path)
ldbparams.BaseKey = basekey
return storage.NewLDBStore(ldbparams)
return localstore.New(path, basekey, nil)
}

func decodeIndex(data []byte, index *dpaDBIndex) error {
dec := rlp.NewStream(bytes.NewReader(data), 0)
return dec.Decode(index)
}

func getDataKey(idx uint64, po uint8) []byte {
key := make([]byte, 10)
key[0] = keyData
key[1] = po
binary.BigEndian.PutUint64(key[2:], idx)

return key
}

func exportLegacy(path string, basekey []byte, out io.Writer) (int64, error) {
tw := tar.NewWriter(out)
defer tw.Close()
db, err := leveldb.OpenFile(path, &opt.Options{OpenFilesCacheCapacity: 128})
if err != nil {
return 0, err
}
defer db.Close()

it := db.NewIterator(nil, nil)
defer it.Release()
var count int64
for ok := it.Seek([]byte{legacyKeyIndex}); ok; ok = it.Next() {
key := it.Key()
if (key == nil) || (key[0] != legacyKeyIndex) {
break
}

var index dpaDBIndex

hash := key[1:]
decodeIndex(it.Value(), &index)

po := uint8(chunk.Proximity(basekey, hash))

datakey := getDataKey(index.Idx, po)
data, err := db.Get(datakey, nil)
if err != nil {
log.Crit(fmt.Sprintf("Chunk %x found but could not be accessed: %v, %x", key, err, datakey))
continue
}

hdr := &tar.Header{
Name: hex.EncodeToString(hash),
Mode: 0644,
Size: int64(len(data)),
}
if err := tw.WriteHeader(hdr); err != nil {
return count, err
}
if _, err := tw.Write(data); err != nil {
return count, err
}
count++
}

return count, nil
}
3 changes: 2 additions & 1 deletion cmd/swarm/explore.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"os"

"github.com/ethereum/go-ethereum/cmd/utils"
"github.com/ethereum/go-ethereum/swarm/chunk"
"github.com/ethereum/go-ethereum/swarm/storage"
"gopkg.in/urfave/cli.v1"
)
Expand All @@ -47,7 +48,7 @@ func hashes(ctx *cli.Context) {
}
defer f.Close()

fileStore := storage.NewFileStore(&storage.FakeChunkStore{}, storage.NewFileStoreParams())
fileStore := storage.NewFileStore(&storage.FakeChunkStore{}, storage.NewFileStoreParams(), chunk.NewTags())
refs, err := fileStore.GetAllReferences(context.TODO(), f, false)
if err != nil {
utils.Fatalf("%v\n", err)
Expand Down
Loading