/** * special iterator for BufferedObjectIndex: iterates only objects from the buffer. The use case * for this iterator is given if first elements are iterated and then all iterated elements are * deleted from the index. To minimize the IO load the buffer is filled from the backend in such a * way that it creates a minimum of Read/Write-Head operations which is done using the removeOne() * method. The buffer will be filled with the demanded number of records. The given load value * does not denote the number of removeOne() operations but the number of records that are missing * in the buffer to provide the give load number of record entries. The given load number must not * exceed the maximal number of entries in the buffer. To give room for put()-inserts while the * iterator is running it is recommended to set the load value at maximum to the maximum number of * entries in the buffer divided by two. * * @param load number of records that shall be in the buffer when returning the buffer iterator * @return an iterator of the elements in the buffer. * @throws IOException */ public HandleSet keysFromBuffer(final int load) throws IOException { if (load > this.buffersize) throw new IOException("buffer load size exceeded"); synchronized (this.backend) { int missing = Math.min(this.backend.size(), load - this.buffer.size()); while (missing-- > 0) { try { this.buffer.put(this.backend.removeOne()); } catch (final SpaceExceededException e) { ConcurrentLog.logException(e); break; } } final HandleSet handles = new RowHandleSet( this.buffer.row().primaryKeyLength, this.buffer.row().objectOrder, this.buffer.size()); final Iterator<byte[]> i = this.buffer.keys(); while (i.hasNext()) { try { handles.put(i.next()); } catch (final SpaceExceededException e) { ConcurrentLog.logException(e); break; } } handles.optimize(); return handles; } }