Ejemplo n.º 1
0
 /** Read the page from the disk. */
 private void read() {
   data.reset();
   data.readByte();
   data.readShortInt();
   trunk = data.readInt();
   logKey = data.readInt();
 }
Ejemplo n.º 2
0
 /**
  * Get the next row from the list.
  *
  * @return the next row
  */
 public Row next() {
   Row r;
   if (file == null) {
     r = list.get(index++);
   } else {
     if (listIndex >= list.size()) {
       list.clear();
       listIndex = 0;
       Data buff = rowBuff;
       buff.reset();
       int min = Constants.FILE_BLOCK_SIZE;
       file.readFully(buff.getBytes(), 0, min);
       int len = buff.readInt() * Constants.FILE_BLOCK_SIZE;
       buff.checkCapacity(len);
       if (len - min > 0) {
         file.readFully(buff.getBytes(), min, len - min);
       }
       while (true) {
         r = readRow(buff);
         if (r == null) {
           break;
         }
         list.add(r);
       }
     }
     index++;
     r = list.get(listIndex++);
   }
   return r;
 }
 /** Read the page from the disk. */
 private void read() {
   data.reset();
   data.readByte();
   data.readShortInt();
   for (int i = 0; i < pageCount; i += 8) {
     int x = data.readByte() & 255;
     used.setByte(i, x);
   }
   full = false;
 }
Ejemplo n.º 4
0
 /**
  * Copy a String from a reader to an output stream.
  *
  * @param source the reader
  * @param target the output stream
  */
 public static void copyString(Reader source, OutputStream target) throws IOException {
   char[] buff = new char[Constants.IO_BUFFER_SIZE];
   Data d = new Data(null, new byte[3 * Constants.IO_BUFFER_SIZE]);
   while (true) {
     int l = source.read(buff);
     if (l < 0) {
       break;
     }
     d.writeStringWithoutLength(buff, l);
     target.write(d.data, 0, d.pos);
     d.reset();
   }
 }
Ejemplo n.º 5
0
 /**
  * Read a row from an input stream.
  *
  * @param in the input stream
  * @param data a temporary buffer
  * @return the row
  */
 public static Row readRow(DataReader in, Data data) throws IOException {
   long key = in.readVarLong();
   int len = in.readVarInt();
   data.reset();
   data.checkCapacity(len);
   in.readFully(data.getBytes(), len);
   int columnCount = data.readVarInt();
   Value[] values = new Value[columnCount];
   for (int i = 0; i < columnCount; i++) {
     values[i] = data.readValue();
   }
   Row row = new Row(values, Row.MEMORY_CALCULATE);
   row.setKey(key);
   return row;
 }
Ejemplo n.º 6
0
 @Override
 public int addRows(ArrayList<Value[]> rows) {
   if (sort != null) {
     sort.sort(rows);
   }
   Data buff = rowBuff;
   long start = file.getFilePointer();
   ByteArrayOutputStream buffer = new ByteArrayOutputStream();
   int bufferLen = 0;
   for (Value[] row : rows) {
     buff.reset();
     buff.writeInt(0);
     for (int j = 0; j < columnCount; j++) {
       Value v = row[j];
       buff.checkCapacity(buff.getValueLen(v));
       buff.writeValue(v);
     }
     buff.fillAligned();
     int len = buff.length();
     buff.setInt(0, len);
     if (maxBufferSize > 0) {
       buffer.write(buff.getBytes(), 0, len);
       bufferLen += len;
       if (bufferLen > maxBufferSize) {
         byte[] data = buffer.toByteArray();
         buffer.reset();
         file.write(data, 0, data.length);
         bufferLen = 0;
       }
     } else {
       file.write(buff.getBytes(), 0, len);
     }
   }
   if (bufferLen > 0) {
     byte[] data = buffer.toByteArray();
     file.write(data, 0, data.length);
   }
   if (sort != null) {
     ResultDiskTape tape = new ResultDiskTape();
     tape.start = start;
     tape.end = file.getFilePointer();
     tapes.add(tape);
   } else {
     mainTape.end = file.getFilePointer();
   }
   rowCount += rows.size();
   return rowCount;
 }
Ejemplo n.º 7
0
 private void readRow(ResultDiskTape tape) {
   int min = Constants.FILE_BLOCK_SIZE;
   Data buff = rowBuff;
   buff.reset();
   file.readFully(buff.getBytes(), 0, min);
   int len = buff.readInt();
   buff.checkCapacity(len);
   if (len - min > 0) {
     file.readFully(buff.getBytes(), min, len - min);
   }
   tape.pos += len;
   Value[] row = new Value[columnCount];
   for (int k = 0; k < columnCount; k++) {
     row[k] = buff.readValue();
   }
   tape.buffer.add(row);
 }
Ejemplo n.º 8
0
 /**
  * A record is added to a table, or removed from a table.
  *
  * @param session the session
  * @param tableId the table id
  * @param row the row to add
  * @param add true if the row is added, false if it is removed
  */
 void logAddOrRemoveRow(Session session, int tableId, Row row, boolean add) {
   if (trace.isDebugEnabled()) {
     trace.debug(
         "log "
             + (add ? "+" : "-")
             + " s: "
             + session.getId()
             + " table: "
             + tableId
             + " row: "
             + row);
   }
   session.addLogPos(logSectionId, logPos);
   logPos++;
   Data data = dataBuffer;
   data.reset();
   int columns = row.getColumnCount();
   data.writeVarInt(columns);
   data.checkCapacity(row.getByteCount(data));
   if (session.isRedoLogBinaryEnabled()) {
     for (int i = 0; i < columns; i++) {
       data.writeValue(row.getValue(i));
     }
   } else {
     for (int i = 0; i < columns; i++) {
       Value v = row.getValue(i);
       if (v.getType() == Value.BYTES) {
         data.writeValue(ValueNull.INSTANCE);
       } else {
         data.writeValue(v);
       }
     }
   }
   Data buffer = getBuffer();
   buffer.writeByte((byte) (add ? ADD : REMOVE));
   buffer.writeVarInt(session.getId());
   buffer.writeVarInt(tableId);
   buffer.writeVarLong(row.getKey());
   if (add) {
     buffer.writeVarInt(data.length());
     buffer.checkCapacity(data.length());
     buffer.write(data.getBytes(), 0, data.length());
   }
   write(buffer);
 }
Ejemplo n.º 9
0
 private void write(Data data) {
   pageOut.write(data.getBytes(), 0, data.length());
   data.reset();
 }
Ejemplo n.º 10
0
 private static void initBuffer(Data buff) {
   buff.reset();
   buff.writeInt(0);
 }