示例#1
0
// NewWriter create new initialized table writer.
func NewWriter(w desc.Writer, o opt.OptionsGetter) *Writer {
	t := &Writer{w: w, o: o, cmp: o.GetComparer()}
	// Creating blocks
	t.data = block.NewWriter(o.GetBlockRestartInterval())
	t.index = block.NewWriter(1)
	filter := o.GetFilter()
	if filter != nil {
		t.filter = block.NewFilterWriter(filter)
		t.filter.Generate(0)
	}
	t.lblock = new(bInfo)
	return t
}
示例#2
0
// Finish finalize the table. No Add(), Flush() or Finish() is possible
// beyond this, doing so will raise panic.
func (t *Writer) Finish() (err error) {
	if t.closed {
		panic("operation on closed table writer")
	}

	err = t.Flush()
	if err != nil {
		return
	}

	t.closed = true

	// Write filter block
	fi := new(bInfo)
	if t.filter != nil {
		err = t.write(t.filter.Finish(), fi, true)
		if err != nil {
			return
		}
	}

	// Write meta block
	meta := block.NewWriter(t.o.GetBlockRestartInterval())
	if t.filter != nil {
		filter := t.o.GetFilter()
		key := []byte("filter." + filter.Name())
		meta.Add(key, fi.encode())
	}
	mb := new(bInfo)
	err = t.write(meta.Finish(), mb, false)
	if err != nil {
		return
	}

	// Write index block
	if t.pindex {
		suc := t.cmp.Successor(t.lkey)
		t.index.Add(suc, t.lblock.encode())
		t.pindex = false
	}
	ib := new(bInfo)
	err = t.write(t.index.Finish(), ib, false)
	if err != nil {
		return
	}

	// Write footer
	var n int
	n, err = writeFooter(t.w, mb, ib)
	if err != nil {
		return
	}
	t.off += n

	return
}
示例#3
0
func (p *stConstructor_Block) init(t *testing.T, ho *stHarnessOpt) error {
	p.t = t
	p.bw = block.NewWriter(3)
	return nil
}