Status FinishCompactionOutputFile(CompactionState compact, Iterator input) {
		assert (compact != null);
		assert (compact.outfile != null);
		assert (compact.builder != null);

		long output_number = compact.current_output().number;
		assert (output_number != 0);

		// Check for iterator errors
		Status s = input.status();
		long current_entries = compact.builder.NumEntries();
		if (s.ok()) {
			s = compact.builder.Finish();
		} else {
			compact.builder.Abandon();
		}
		long current_bytes = compact.builder.FileSize();
		compact.current_output().file_size = current_bytes;
		compact.total_bytes += current_bytes;
		compact.builder = null;

		// Finish and check for file errors
		if (s.ok()) {
			s = compact.outfile.Sync();
		}
		if (s.ok()) {
			s = compact.outfile.Close();
		}
		compact.outfile = null;

		if (s.ok() && current_entries > 0) {
			// Verify that the table is usable
			Iterator iter = table_cache_.NewIterator(new ReadOptions(),
					output_number, current_bytes, null);
			s = iter.status();
			iter = null;
			// wlu, 2012-7-10, bugFix: s !=null
			if (s != null && s.ok()) {
				LOG.info("Generated table #" + output_number + ": "
						+ current_entries + " keys, " + current_bytes
						+ " bytes");
			}
			// wlu, 2012-7-10, bugFix: s ==null ...
			if (s == null) {
				s = new Status();
			}
		}
		return s;
	}