private void writeLevel0Table(MemTable mem, VersionEdit edit, Version base) throws IOException { Preconditions.checkState(mutex.isHeldByCurrentThread()); // skip empty mem table if (mem.isEmpty()) { return; } // write the memtable to a new sstable long fileNumber = versions.getNextFileNumber(); pendingOutputs.add(fileNumber); mutex.unlock(); FileMetaData meta; try { meta = buildTable(mem, fileNumber); } finally { mutex.lock(); } pendingOutputs.remove(fileNumber); // Note that if file size is zero, the file has been deleted and // should not be added to the manifest. int level = 0; if (meta != null && meta.getFileSize() > 0) { Slice minUserKey = meta.getSmallest().getUserKey(); Slice maxUserKey = meta.getLargest().getUserKey(); if (base != null) { level = base.pickLevelForMemTableOutput(minUserKey, maxUserKey); } edit.addFile(level, meta); } }