Skip to content

Commit

Permalink
Merge pull request minio#41 from harshavardhana/pr_out_make_use_of_lr…
Browse files Browse the repository at this point in the history
…u_and_higher_order_erasure_functions

Make use of LRU and higher order erasure functions
  • Loading branch information
Harshavardhana committed Nov 24, 2014
2 parents 95e2e47 + 6592ef3 commit a1aafb9
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 18 deletions.
3 changes: 1 addition & 2 deletions cmd/minio-decode/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,9 @@ func main() {

// set up encoder
erasureParameters, _ := erasure.ValidateParams(k, m, 8, erasure.CAUCHY)
encoder := erasure.NewEncoder(erasureParameters)

// decode data
decodedData, err := encoder.Decode(chunks, length)
decodedData, err := erasure.Decode(chunks, erasureParameters, length)
if err != nil {
log.Fatal(err)
}
Expand Down
4 changes: 1 addition & 3 deletions cmd/minio-encode/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,8 @@ func main() {

// set up encoder
erasureParameters, _ := erasure.ValidateParams(k, m, 8, erasure.CAUCHY)
encoder := erasure.NewEncoder(erasureParameters)

// encode data
encodedData, length := encoder.Encode(input)
encodedData, length := erasure.Encode(input, erasureParameters)

// write encoded data out
for key, data := range encodedData {
Expand Down
9 changes: 3 additions & 6 deletions erasure/cauchy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,8 @@ func Test(t *testing.T) { TestingT(t) }

func (s *MySuite) TestCachyEncode(c *C) {
ep, _ := ValidateParams(10, 5, 8, CAUCHY)
p := NewEncoder(ep)

data := make([]byte, 1000)
_, length := p.Encode(data)
_, length := Encode(data, ep)
c.Assert(length, Equals, len(data))
}

Expand All @@ -41,8 +39,7 @@ func (s *MySuite) TestCauchyDecode(c *C) {

data := []byte("Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.")

p := NewEncoder(ep)
chunks, length := p.Encode(data)
chunks, length := Encode(data, ep)
c.Assert(length, Equals, len(data))

chunks[0] = nil
Expand All @@ -51,7 +48,7 @@ func (s *MySuite) TestCauchyDecode(c *C) {
chunks[9] = nil
chunks[13] = nil

recovered_data, err := p.Decode(chunks, length)
recovered_data, err := Decode(chunks, ep, length)
c.Assert(err, Not(IsNil))

c.Assert(recovered_data, DeepEquals, data)
Expand Down
2 changes: 1 addition & 1 deletion erasure/decode.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,6 @@ func (e *Encoder) Decode(chunks [][]byte, length int) ([]byte, error) {
return recovered_output[:length], nil
}

func Decode(chunks [][]byte, ep EncoderParams, length int) (block []byte, err error) {
func Decode(chunks [][]byte, ep *EncoderParams, length int) (block []byte, err error) {
return GetEncoder(ep).Decode(chunks, length)
}
4 changes: 2 additions & 2 deletions erasure/encode.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,10 +200,10 @@ func (e *Encoder) Encode(block []byte) ([][]byte, int) {
return chunks, block_len
}

func GetEncoder(ep EncoderParams) *Encoder {
func GetEncoder(ep *EncoderParams) *Encoder {
return DefaultCache.GetC(ep)
}

func Encode(data []byte, ep EncoderParams) (chunks [][]byte, length int) {
func Encode(data []byte, ep *EncoderParams) (chunks [][]byte, length int) {
return GetEncoder(ep).Encode(data)
}
8 changes: 4 additions & 4 deletions erasure/lru.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,17 @@ func GetCache(capacity int) *Cache {
}

// ``GetC()`` -- Grab encoder from LRU
func (c *Cache) GetC(ep EncoderParams) *Encoder {
func (c *Cache) GetC(ep *EncoderParams) *Encoder {
if encoder, ret := c._Get(ep); ret {
return encoder
}
encoder := NewEncoder(&ep)
encoder := NewEncoder(ep)
c._Put(ep, encoder)
return encoder
}

// ``_Get()`` -- Get key from existing LRU
func (c *Cache) _Get(ep EncoderParams) (*Encoder, bool) {
func (c *Cache) _Get(ep *EncoderParams) (*Encoder, bool) {
c.mutex.RLock()
defer c.mutex.RUnlock()
if encoder, ret := c.cache.Get(ep); ret {
Expand All @@ -57,7 +57,7 @@ func (c *Cache) _Get(ep EncoderParams) (*Encoder, bool) {
}

// ``_Put()`` -- Add key to existing LRU
func (c *Cache) _Put(ep EncoderParams, encoder *Encoder) {
func (c *Cache) _Put(ep *EncoderParams, encoder *Encoder) {
c.mutex.Lock()
defer c.mutex.Unlock()
c.cache.Add(ep, encoder)
Expand Down

0 comments on commit a1aafb9

Please sign in to comment.