diff options
Diffstat (limited to 'swarm/storage')
-rw-r--r-- | swarm/storage/chunker.go | 19 | ||||
-rw-r--r-- | swarm/storage/chunker_test.go | 4 | ||||
-rw-r--r-- | swarm/storage/memstore.go | 2 | ||||
-rw-r--r-- | swarm/storage/netstore.go | 10 | ||||
-rw-r--r-- | swarm/storage/pyramid.go | 28 |
5 files changed, 33 insertions, 30 deletions
diff --git a/swarm/storage/chunker.go b/swarm/storage/chunker.go index 0454828b9..98cd6e75e 100644 --- a/swarm/storage/chunker.go +++ b/swarm/storage/chunker.go @@ -50,7 +50,6 @@ data_{i} := size(subtree_{i}) || key_{j} || key_{j+1} .... || key_{j+n-1} The underlying hash function is configurable */ - /* Tree chunker is a concrete implementation of data chunking. This chunker works in a simple way, it builds a tree out of the document so that each node either represents a chunk of real data or a chunk of data representing an branching non-leaf node of the tree. In particular each such non-leaf chunk will represent is a concatenation of the hash of its respective children. This scheme simultaneously guarantees data integrity as well as self addressing. Abstract nodes are transparent since their represented size component is strictly greater than their maximum data size, since they encode a subtree. @@ -61,17 +60,17 @@ The hashing itself does use extra copies and allocation though, since it does ne var ( errAppendOppNotSuported = errors.New("Append operation not supported") - errOperationTimedOut = errors.New("operation timed out") + errOperationTimedOut = errors.New("operation timed out") ) type TreeChunker struct { branches int64 hashFunc SwarmHasher // calculated - hashSize int64 // self.hashFunc.New().Size() - chunkSize int64 // hashSize* branches - workerCount int64 // the number of worker routines used - workerLock sync.RWMutex // lock for the worker count + hashSize int64 // self.hashFunc.New().Size() + chunkSize int64 // hashSize* branches + workerCount int64 // the number of worker routines used + workerLock sync.RWMutex // lock for the worker count } func NewTreeChunker(params *ChunkerParams) (self *TreeChunker) { @@ -124,7 +123,6 @@ func (self *TreeChunker) Split(data io.Reader, size int64, chunkC chan *Chunk, s panic("chunker must be initialised") } - jobC := make(chan *hashJob, 2*ChunkProcessors) wg := &sync.WaitGroup{} errC := make(chan error) @@ -164,7 +162,6 @@ func (self *TreeChunker) Split(data io.Reader, size int64, chunkC chan *Chunk, s close(errC) }() - defer close(quitC) select { case err := <-errC: @@ -172,7 +169,7 @@ func (self *TreeChunker) Split(data io.Reader, size int64, chunkC chan *Chunk, s return nil, err } case <-time.NewTimer(splitTimeout).C: - return nil,errOperationTimedOut + return nil, errOperationTimedOut } return key, nil @@ -208,9 +205,9 @@ func (self *TreeChunker) split(depth int, treeSize int64, key Key, data io.Reade } // dept > 0 // intermediate chunk containing child nodes hashes - branchCnt := int64((size + treeSize - 1) / treeSize) + branchCnt := (size + treeSize - 1) / treeSize - var chunk []byte = make([]byte, branchCnt*self.hashSize+8) + var chunk = make([]byte, branchCnt*self.hashSize+8) var pos, i int64 binary.LittleEndian.PutUint64(chunk[0:8], uint64(size)) diff --git a/swarm/storage/chunker_test.go b/swarm/storage/chunker_test.go index b41d7dd33..6178a7bb1 100644 --- a/swarm/storage/chunker_test.go +++ b/swarm/storage/chunker_test.go @@ -77,7 +77,7 @@ func (self *chunkerTester) Split(chunker Splitter, data io.Reader, size int64, c key, err = chunker.Split(data, size, chunkC, swg, nil) if err != nil && expectedError == nil { - err = errors.New(fmt.Sprintf("Split error: %v", err)) + err = fmt.Errorf("Split error: %v", err) } if chunkC != nil { @@ -123,7 +123,7 @@ func (self *chunkerTester) Append(chunker Splitter, rootKey Key, data io.Reader, key, err = chunker.Append(rootKey, data, chunkC, swg, nil) if err != nil && expectedError == nil { - err = errors.New(fmt.Sprintf("Append error: %v", err)) + err = fmt.Errorf("Append error: %v", err) } if chunkC != nil { diff --git a/swarm/storage/memstore.go b/swarm/storage/memstore.go index 155dd0088..3cb25ac62 100644 --- a/swarm/storage/memstore.go +++ b/swarm/storage/memstore.go @@ -78,7 +78,7 @@ type memTree struct { func newMemTree(b uint, parent *memTree, pidx uint) (node *memTree) { node = new(memTree) node.bits = b - node.width = 1 << uint(b) + node.width = 1 << b node.subtree = make([]*memTree, node.width) node.access = make([]uint64, node.width-1) node.parent = parent diff --git a/swarm/storage/netstore.go b/swarm/storage/netstore.go index 7b0612edc..5d4f17deb 100644 --- a/swarm/storage/netstore.go +++ b/swarm/storage/netstore.go @@ -57,15 +57,21 @@ type StoreParams struct { Radius int } -func NewStoreParams(path string) (self *StoreParams) { +//create params with default values +func NewDefaultStoreParams() (self *StoreParams) { return &StoreParams{ - ChunkDbPath: filepath.Join(path, "chunks"), DbCapacity: defaultDbCapacity, CacheCapacity: defaultCacheCapacity, Radius: defaultRadius, } } +//this can only finally be set after all config options (file, cmd line, env vars) +//have been evaluated +func (self *StoreParams) Init(path string) { + self.ChunkDbPath = filepath.Join(path, "chunks") +} + // netstore contructor, takes path argument that is used to initialise dbStore, // the persistent (disk) storage component of LocalStore // the second argument is the hive, the connection/logistics manager for the node diff --git a/swarm/storage/pyramid.go b/swarm/storage/pyramid.go index e3be2a987..f2e85cb5b 100644 --- a/swarm/storage/pyramid.go +++ b/swarm/storage/pyramid.go @@ -27,7 +27,7 @@ import ( /* The main idea of a pyramid chunker is to process the input data without knowing the entire size apriori. For this to be achieved, the chunker tree is built from the ground up until the data is exhausted. - This opens up new aveneus such as easy append and other sort of modifications to the tree therby avoiding + This opens up new aveneus such as easy append and other sort of modifications to the tree thereby avoiding duplication of data chunks. @@ -123,7 +123,7 @@ type PyramidChunker struct { hashSize int64 branches int64 workerCount int64 - workerLock sync.RWMutex + workerLock sync.RWMutex } func NewPyramidChunker(params *ChunkerParams) (self *PyramidChunker) { @@ -327,7 +327,7 @@ func (self *PyramidChunker) loadTree(chunkLevel [][]*TreeEntry, key Key, chunkC // Add the root chunk entry branchCount := int64(len(chunk.SData)-8) / self.hashSize newEntry := &TreeEntry{ - level: int(depth - 1), + level: depth - 1, branchCount: branchCount, subtreeSize: uint64(chunk.Size), chunk: chunk.SData, @@ -352,7 +352,7 @@ func (self *PyramidChunker) loadTree(chunkLevel [][]*TreeEntry, key Key, chunkC } bewBranchCount := int64(len(newChunk.SData)-8) / self.hashSize newEntry := &TreeEntry{ - level: int(lvl - 1), + level: lvl - 1, branchCount: bewBranchCount, subtreeSize: uint64(newChunk.Size), chunk: newChunk.SData, @@ -391,7 +391,7 @@ func (self *PyramidChunker) prepareChunks(isAppend bool, chunkLevel [][]*TreeEnt parent := NewTreeEntry(self) var unFinishedChunk *Chunk - if isAppend == true && len(chunkLevel[0]) != 0 { + if isAppend && len(chunkLevel[0]) != 0 { lastIndex := len(chunkLevel[0]) - 1 ent := chunkLevel[0][lastIndex] @@ -451,7 +451,7 @@ func (self *PyramidChunker) prepareChunks(isAppend bool, chunkLevel [][]*TreeEnt } } - // Data ended in chunk boundry.. just signal to start bulding tree + // Data ended in chunk boundary.. just signal to start bulding tree if n == 0 { self.buildTree(isAppend, chunkLevel, parent, chunkWG, jobC, quitC, true, rootKey) break @@ -512,7 +512,7 @@ func (self *PyramidChunker) buildTree(isAppend bool, chunkLevel [][]*TreeEntry, } } - if compress == false && last == false { + if !compress && !last { return } @@ -522,7 +522,7 @@ func (self *PyramidChunker) buildTree(isAppend bool, chunkLevel [][]*TreeEntry, for lvl := int64(ent.level); lvl < endLvl; lvl++ { lvlCount := int64(len(chunkLevel[lvl])) - if lvlCount == 1 && last == true { + if lvlCount == 1 && last { copy(rootKey, chunkLevel[lvl][0].key) return } @@ -540,7 +540,7 @@ func (self *PyramidChunker) buildTree(isAppend bool, chunkLevel [][]*TreeEntry, nextLvlCount = int64(len(chunkLevel[lvl+1]) - 1) tempEntry = chunkLevel[lvl+1][nextLvlCount] } - if isAppend == true && tempEntry != nil && tempEntry.updatePending == true { + if isAppend && tempEntry != nil && tempEntry.updatePending { updateEntry := &TreeEntry{ level: int(lvl + 1), branchCount: 0, @@ -585,9 +585,9 @@ func (self *PyramidChunker) buildTree(isAppend bool, chunkLevel [][]*TreeEntry, } - if isAppend == false { + if !isAppend { chunkWG.Wait() - if compress == true { + if compress { chunkLevel[lvl] = nil } } @@ -599,7 +599,7 @@ func (self *PyramidChunker) enqueueTreeChunk(chunkLevel [][]*TreeEntry, ent *Tre if ent != nil { // wait for data chunks to get over before processing the tree chunk - if last == true { + if last { chunkWG.Wait() } @@ -612,7 +612,7 @@ func (self *PyramidChunker) enqueueTreeChunk(chunkLevel [][]*TreeEntry, ent *Tre } // Update or append based on weather it is a new entry or being reused - if ent.updatePending == true { + if ent.updatePending { chunkWG.Wait() chunkLevel[ent.level][ent.index] = ent } else { @@ -634,4 +634,4 @@ func (self *PyramidChunker) enqueueDataChunk(chunkData []byte, size uint64, pare return pkey -}
\ No newline at end of file +} |