code: func (db *DB) OpenTransaction() (*Transaction, error) {
  	if err := db.ok(); err != nil {
  		return nil, err
  	}
  
  	// The write happen synchronously.
  	select {
  	case db.writeLockC <- struct{}{}:
  	case err := <-db.compPerErrC:
  		return nil, err
  	case <-db.closeC:
  		return nil, ErrClosed
  	}
  
  	if db.tr != nil {
  		panic("leveldb: has open transaction")
  	}
  
  	// Flush current memdb.
  	if db.mem != nil && db.mem.Len() != 0 {
  		if _, err := db.rotateMem(0, true); err != nil {
  			return nil, err
  		}
  	}
  
  	// Wait compaction when certain threshold reached.
  	if err := db.waitCompaction(); err != nil {
  		return nil, err
  	}
  
  	tr := &Transaction{
  		db:  db,
  		seq: db.seq,
  		mem: db.mpoolGet(0),
  	}
  	tr.mem.incref()
  	db.tr = tr
  	return tr, nil
  }
docs: // OpenTransaction opens an atomic DB transaction. Only one transaction can be
  // opened at a time. Subsequent call to Write and OpenTransaction will be blocked
  // until in-flight transaction is committed or discarded.
  // The returned transaction handle is safe for concurrent use.
  //
  // Transaction is expensive and can overwhelm compaction, especially if
  // transaction size is small. Use with caution.
  //
  // The transaction must be closed once done, either by committing or discarding
  // the transaction.
  // Closing the DB will discard open transaction.