-
Notifications
You must be signed in to change notification settings - Fork 175
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Adds nil support for Kafka's nil message semantics. Receiving a nil message in a View will now remove the associated key from the local cache. * Adds Delete() method on Context. Calling delete will evict the key from the local cache and send a nil message to the group table in Kafka under the associated key.
- Loading branch information
1 parent
eea4c59
commit 6bf0ab9
Showing
6 changed files
with
235 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
package storage | ||
|
||
import ( | ||
"fmt" | ||
"io" | ||
"os" | ||
"path/filepath" | ||
) | ||
|
||
type file struct { | ||
file io.WriteCloser | ||
codec Codec | ||
recovered bool | ||
|
||
bytesWritten int64 | ||
} | ||
|
||
func NewFile(path string, part int32, codec Codec) (Storage, error) { | ||
if err := os.MkdirAll(path, os.ModePerm); err != nil { | ||
return nil, fmt.Errorf("error creating storage directory: %v", err) | ||
} | ||
|
||
f, err := os.OpenFile(filepath.Join(path, fmt.Sprintf("part-%d", part)), os.O_CREATE|os.O_RDWR|os.O_APPEND, os.ModePerm) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return &file{file: f}, nil | ||
} | ||
|
||
func (f *file) Recovered() bool { | ||
return f.recovered | ||
} | ||
|
||
func (f *file) MarkRecovered() error { | ||
f.recovered = true | ||
return nil | ||
} | ||
|
||
func (f *file) Has(key string) (bool, error) { | ||
return false, nil | ||
} | ||
|
||
func (f *file) Get(key string) (interface{}, error) { | ||
return nil, nil | ||
} | ||
|
||
func (f *file) Set(key string, val interface{}) error { | ||
data, err := f.codec.Encode(val) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return f.SetEncoded(key, data) | ||
} | ||
|
||
func (f *file) SetEncoded(key string, val []byte) error { | ||
num, err := f.file.Write(val) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
f.bytesWritten += int64(num) | ||
|
||
if _, err := f.file.Write([]byte("\n")); err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (f *file) Delete(string) error { | ||
return nil | ||
} | ||
|
||
func (f *file) GetOffset(def int64) (int64, error) { | ||
return def, nil | ||
} | ||
|
||
func (f *file) SetOffset(val int64) error { | ||
return nil | ||
} | ||
|
||
func (f *file) Iterator() (Iterator, error) { | ||
return new(NullIter), nil | ||
} | ||
|
||
func (f *file) Open() error { | ||
return nil | ||
} | ||
|
||
func (f *file) Close() error { | ||
return f.file.Close() | ||
} | ||
|
||
func (f *file) Sync() {} |