mirror of
https://github.com/minio/minio.git
synced 2024-12-23 21:55:53 -05:00
Make use of LRU and higher order erasure functions
This commit is contained in:
parent
95e2e472cd
commit
6592ef3bd2
@ -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)
|
||||
}
|
||||
|
@ -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 {
|
||||
|
@ -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))
|
||||
}
|
||||
|
||||
@ -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
|
||||
@ -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)
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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 {
|
||||
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user