Write implements Wal.Write.
(l *kt.Log)
| 45 | |
| 46 | // Write implements Wal.Write. |
| 47 | func (p *MemWal) Write(l *kt.Log) (err error) { |
| 48 | if atomic.LoadUint32(&p.closed) == 1 { |
| 49 | err = ErrWalClosed |
| 50 | return |
| 51 | } |
| 52 | |
| 53 | if l == nil { |
| 54 | err = ErrInvalidLog |
| 55 | return |
| 56 | } |
| 57 | |
| 58 | p.Lock() |
| 59 | defer p.Unlock() |
| 60 | |
| 61 | if _, exists := p.revIndex[l.Index]; exists { |
| 62 | err = ErrAlreadyExists |
| 63 | return |
| 64 | } |
| 65 | |
| 66 | offset := atomic.AddUint64(&p.offset, 1) - 1 |
| 67 | p.logs = append(p.logs, nil) |
| 68 | copy(p.logs[offset+1:], p.logs[offset:]) |
| 69 | p.logs[offset] = l |
| 70 | p.revIndex[l.Index] = int(offset) |
| 71 | |
| 72 | return |
| 73 | } |
| 74 | |
| 75 | // Read implements Wal.Read. |
| 76 | func (p *MemWal) Read() (l *kt.Log, err error) { |
no outgoing calls