Skip to content

Commit

Permalink
rename
Browse files Browse the repository at this point in the history
  • Loading branch information
travisjeffery committed Oct 11, 2016
1 parent cfc462a commit b106408
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 47 deletions.
18 changes: 17 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
# Strolla

Kafka/distributed commit log service in Go.

## Goals of this project:

- Implement Kafka (distributed commit log service) in Go
- Implement Kafka in Go
- Make operating simpler
- Distribute a single binary
- Improve performance
- Use Raft for consensus
- Learn a lot and have fun

## TODO

Expand All @@ -14,4 +19,15 @@
- [ ] Distributed replication
- [ ] Etc...

## License

MIT

---

- [travisjeffery.com](http://travisjeffery.com)
- GitHub [@travisjeffery](https://github.com/travisjeffery)
- Twitter [@travisjeffery](https://twitter.com/travisjeffery)
- Medium [@travisjeffery](https://medium.com/@travisjeffery)


2 changes: 1 addition & 1 deletion commitlog/commitlog.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func (l *CommitLog) split() error {
}

func (l *CommitLog) newestOffset() int64 {
return l.activeSegment().NewestOffset()
return l.activeSegment().NextOffset()
}

func (l *CommitLog) activeSegment() *segment {
Expand Down
40 changes: 20 additions & 20 deletions commitlog/segment.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ const (
)

type segment struct {
writer io.Writer
reader io.Reader
log *os.File
index *os.File
baseOffset int64
newestOffset int64
bytes int64
maxBytes int64
writer io.Writer
reader io.Reader
log *os.File
index *os.File
baseOffset int64
nextOffset int64
bytes int64
maxBytes int64
}

func NewSegment(path string, baseOffset int64, maxBytes int64) (*segment, error) {
Expand All @@ -44,21 +44,21 @@ func NewSegment(path string, baseOffset int64, maxBytes int64) (*segment, error)
}

s := &segment{
log: log,
index: index,
writer: log,
reader: log,
bytes: fi.Size(),
maxBytes: maxBytes,
baseOffset: baseOffset,
newestOffset: baseOffset,
log: log,
index: index,
writer: log,
reader: log,
bytes: fi.Size(),
maxBytes: maxBytes,
baseOffset: baseOffset,
nextOffset: baseOffset,
}

return s, nil
}

func (s *segment) NewestOffset() int64 {
return s.newestOffset
func (s *segment) NextOffset() int64 {
return s.nextOffset
}

func (s *segment) IsFull() bool {
Expand All @@ -71,12 +71,12 @@ func (s *segment) Write(p []byte) (n int, err error) {
return n, errors.Wrap(err, "log write failed")
}

_, err = s.index.Write([]byte(fmt.Sprintf("%d,%d\n", s.newestOffset, s.bytes)))
_, err = s.index.Write([]byte(fmt.Sprintf("%d,%d\n", s.nextOffset, s.bytes)))
if err != nil {
return 0, errors.Wrap(err, "index write failed")
}

s.newestOffset += 1
s.nextOffset += 1
s.bytes += int64(n)

return n, nil
Expand Down
5 changes: 0 additions & 5 deletions main.go

This file was deleted.

30 changes: 10 additions & 20 deletions clog.go → strolla.go
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
package clog
package strolla

import (
"encoding/json"
"flag"
"io"
"io/ioutil"
"log"
"os"
"path/filepath"

"github.com/pkg/errors"
"github.com/travisjeffery/strolla/commitlog"
)

var (
logDirFlag = flag.String("log-dir", "/tmp/clog-logs", "A comma separated list of directories under which to store log files")
logDirFlag = flag.String("logdir", "/tmp/strolla", "A comma separated list of directories under which to store log files")
)

const configFile = "config.json"

type Clog struct {
type Strolla struct {
LogDir string
}

func NewClog(logDir string) (*Clog, error) {
func NewStrolla(logDir string) (*Strolla, error) {
ld, err := os.Stat(logDir)

if os.IsNotExist(err) {
Expand All @@ -35,14 +35,14 @@ func NewClog(logDir string) (*Clog, error) {
return nil, errors.Wrap(err, "log directory isn't a directory")
}

c := &Clog{
c := &Strolla{
LogDir: logDir,
}

return c, nil
}

func (c *Clog) initTopics() (err error) {
func (c *Strolla) initTopics() (err error) {
fis, err := ioutil.ReadDir(c.LogDir)

if err != nil {
Expand All @@ -65,7 +65,7 @@ func (c *Clog) initTopics() (err error) {
type TopicConfig struct {
}

func (c *Clog) initTopic(name string) error {
func (c *Strolla) initTopic(name string) error {
topicPath := filepath.Join(c.LogDir, name)
configPath := filepath.Join(topicPath, configFile)

Expand All @@ -90,24 +90,14 @@ func (c *Clog) initTopic(name string) error {
type Topic struct {
name string
config TopicConfig
log *Log
log *commitlog.CommitLog
writer io.Writer
}

func newTopic(config TopicConfig) *Topic {
return &Topic{}
}

func (c *Clog) register(name string, topic *Topic) error {
func (c *Strolla) register(name string, topic *Topic) error {

}

func main() {
flag.Parse()

_, err := NewClog(*logDirFlag)

if err != nil {
log.Println(err)
}
}

0 comments on commit b106408

Please sign in to comment.