columnNumber = creator.getColumnNumber(idxCol.getName());
if(columnNumber == COLUMN_UNUSED) {
// should never happen as this is validated before
- // FIXME
- // throw new IllegalArgumentException(
- // withErrorContext(
- // "Column with name " + idxCol.getName() + " not found",
- // creator.getDatabase(), creator.getName(), idx.getName()));
+ throw new IllegalArgumentException(
+ withErrorContext(
+ "Column with name " + idxCol.getName() + " not found",
+ creator.getDatabase(), creator.getTableName(), idx.getName()));
}
}
if(isLongVal) {
// allocate usage maps for the long value col
- Map.Entry<Integer,Integer> umapInfo = addUsageMaps(2);
+ Map.Entry<Integer,Integer> umapInfo = addUsageMaps(2, null);
System.out.println("FOO created umap " + umapInfo);
DBMutator.ColumnState colState = mutator.getColumnState(column);
colState.setUmapPageNumber(umapInfo.getKey());
ByteUtil.forward(tableBuffer, (_indexCount *
format.SIZE_INDEX_COLUMN_BLOCK));
- // write index data def
+ // allocate usage maps and root page
DBMutator.IndexDataState idxDataState = mutator.getIndexDataState(index);
+ int rootPageNumber = getPageChannel().allocateNewPage();
+ Map.Entry<Integer,Integer> umapInfo = addUsageMaps(1, rootPageNumber);
+ System.out.println("FOO created umap " + umapInfo);
+ idxDataState.setRootPageNumber(rootPageNumber);
+ idxDataState.setUmapPageNumber(umapInfo.getKey());
+ idxDataState.setUmapRowNumber(umapInfo.getValue().byteValue());
+
+ // write index data def
int idxDataDefPos = tableBuffer.position();
ByteUtil.insertEmptyData(tableBuffer, format.SIZE_INDEX_COLUMN_BLOCK);
IndexData.writeDefinition(mutator, tableBuffer, idxDataState, null);
format.SIZE_INDEX_INFO_BLOCK));
int idxDefPos = tableBuffer.position();
+ ByteUtil.insertEmptyData(tableBuffer, format.SIZE_INDEX_INFO_BLOCK);
IndexImpl.writeDefinition(mutator, index, tableBuffer);
// skip existing index names and write new name
return tableBuffer;
}
- private Map.Entry<Integer,Integer> addUsageMaps(int numMaps) throws IOException
+ private Map.Entry<Integer,Integer> addUsageMaps(
+ int numMaps, Integer firstUsedPage)
+ throws IOException
{
JetFormat format = getFormat();
PageChannel pageChannel = getPageChannel();
for(int i = 0; i < numMaps; ++i) {
umapBuf.putShort(getRowStartOffset(umapRowNum, format), (short)rowStart);
umapBuf.put(rowStart, UsageMap.MAP_TYPE_INLINE);
+
+ if(firstUsedPage != null) {
+ // fill in the first used page of the usage map
+ umapBuf.putInt(rowStart + 1, firstUsedPage);
+ umapBuf.put(rowStart + 5, (byte)1);
+ }
+
rowStart -= umapRowLength;
++umapRowNum;
}
return _index;
}
+ @Override
+ String getTableName() {
+ return _table.getName();
+ }
+
@Override
public int getTdefPageNumber() {
return _table.getTableDefPageNumber();
return _nextPages;
}
+ void resetTdefInfo() {
+ _addedTdefLen = 0;
+ _origTdefLen = 0;
+ _nextPages.clear();
+ }
+
public ColumnImpl addColumn(ColumnBuilder column) throws IOException {
_column = column;
if(_idxDataState.getIndexDataNumber() == _table.getIndexCount()) {
// we need a new backing index data
_table.mutateAddIndexData(this);
+ resetTdefInfo();
}
return _table.mutateAddIndex(this);
+ // FIXME, need to add data to index!!!
+
} finally {
getPageChannel().finishWrite();
}