Hbase1.1.5源码:
HTable类:
@Override
public void put(final Put put) throws IOException {
getBufferedMutator().mutate(put);//放入bufferMutator中
if (autoFlush) {
flushCommits();
}
}
/**
* {@inheritDoc}
* @throws IOException
*/
@Override
public void put(final List<Put> puts) throws IOException {
getBufferedMutator().mutate(puts);放入bufferMutator中
if (autoFlush) {
flushCommits();
}
}
BufferedMutatorImpl类:
@Override
public synchronized void mutate(Mutation m) throws InterruptedIOException,
RetriesExhaustedWithDetailsException {
doMutate(m);
}
@Override
public synchronized void mutate(List<? extends Mutation> ms) throws InterruptedIOException,
RetriesExhaustedWithDetailsException {
for (Mutation m : ms) {
doMutate(m); //调用单条的mutate方法
}
}
private void doMutate(Mutation m) throws InterruptedIOException, RetriesExhaustedWithDetailsException { if (closed) { throw new IllegalStateException("Cannot put when the BufferedMutator is closed."); } if (!(m instanceof Put) && !(m instanceof Delete)) { throw new IllegalArgumentException("Pass a Delete or a Put"); } // This behavior is highly non-intuitive... it does not protect us against // 94-incompatible behavior, which is a timing issue because hasError, the below code // and setter of hasError are not synchronized. Perhaps it should be removed. if (ap.hasError()) { writeAsyncBuffer.add(m); backgroundFlushCommits(true); } if (m instanceof Put) { validatePut((Put) m); } currentWriteBufferSize += m.heapSize(); // 计算字节大小,并累加 writeAsyncBuffer.add(m); // 如果当前的数据字节大小大于阈值,则进行commit while (currentWriteBufferSize > writeBufferSize) { backgroundFlushCommits(false); } }