HBASE-10358 Shell changes for setting consistency per request (yi liang)

This commit is contained in:
Enis Soztutar 2016-05-26 14:20:01 -07:00
parent fdaf3be84f
commit b89d88a193
4 changed files with 19 additions and 9 deletions

View File

@ -282,6 +282,7 @@ EOF
def _get_internal(row, *args) def _get_internal(row, *args)
get = org.apache.hadoop.hbase.client.Get.new(row.to_s.to_java_bytes) get = org.apache.hadoop.hbase.client.Get.new(row.to_s.to_java_bytes)
maxlength = -1 maxlength = -1
count = 0
@converters.clear() @converters.clear()
# Normalize args # Normalize args
@ -370,6 +371,10 @@ EOF
result = @table.get(get) result = @table.get(get)
return nil if result.isEmpty return nil if result.isEmpty
# Get stale info from results
is_stale = result.isStale
count += 1
# Print out results. Result can be Cell or RowResult. # Print out results. Result can be Cell or RowResult.
res = {} res = {}
result.listCells.each do |c| result.listCells.each do |c|
@ -389,7 +394,7 @@ EOF
end end
# If block given, we've yielded all the results, otherwise just return them # If block given, we've yielded all the results, otherwise just return them
return ((block_given?) ? nil : res) return ((block_given?) ? [count, is_stale]: res)
end end
#---------------------------------------------------------------------------------------------- #----------------------------------------------------------------------------------------------
@ -509,6 +514,7 @@ EOF
while iter.hasNext while iter.hasNext
row = iter.next row = iter.next
key = org.apache.hadoop.hbase.util.Bytes::toStringBinary(row.getRow) key = org.apache.hadoop.hbase.util.Bytes::toStringBinary(row.getRow)
is_stale |= row.isStale
row.listCells.each do |c| row.listCells.each do |c|
family = org.apache.hadoop.hbase.util.Bytes::toStringBinary(c.getFamilyArray, family = org.apache.hadoop.hbase.util.Bytes::toStringBinary(c.getFamilyArray,
@ -536,7 +542,7 @@ EOF
end end
scanner.close() scanner.close()
return ((block_given?) ? count : res) return ((block_given?) ? [count, is_stale] : res)
end end
# Apply OperationAttributes to puts/scans/gets # Apply OperationAttributes to puts/scans/gets

View File

@ -84,11 +84,11 @@ EOF
now = Time.now now = Time.now
formatter.header(["COLUMN", "CELL"]) formatter.header(["COLUMN", "CELL"])
table._get_internal(row, *args) do |column, value| count, is_stale = table._get_internal(row, *args) do |column, value|
formatter.row([ column, value ]) formatter.row([ column, value ])
end end
formatter.footer(now) formatter.footer(now, count, is_stale)
end end
end end
end end

View File

@ -109,12 +109,11 @@ EOF
scan = table._hash_to_scan(args) scan = table._hash_to_scan(args)
#actually do the scanning #actually do the scanning
count = table._scan_internal(args, scan) do |row, cells| count, is_stale = table._scan_internal(args, scan) do |row, cells|
formatter.row([ row, cells ]) formatter.row([ row, cells ])
end end
formatter.footer(now, count) formatter.footer(now, count, is_stale)
# if scan metrics were enabled, print them after the results # if scan metrics were enabled, print them after the results
if (scan != nil && scan.isScanMetricsEnabled()) if (scan != nil && scan.isScanMetricsEnabled())
formatter.scan_metrics(scan.getScanMetrics(), args["METRICS"]) formatter.scan_metrics(scan.getScanMetrics(), args["METRICS"])

View File

@ -177,11 +177,16 @@ module Shell
end end
end end
def footer(start_time = nil, row_count = nil) def footer(start_time = nil, row_count = nil, is_stale = false)
return unless start_time return unless start_time
row_count ||= @row_count row_count ||= @row_count
# Only output elapsed time and row count if startTime passed # Only output elapsed time and row count if startTime passed
@out.puts("%d row(s) in %.4f seconds" % [row_count, Time.now - start_time]) @out.print("%d row(s) in %.4f seconds" % [row_count, Time.now - start_time])
if is_stale == true
@out.puts(" (possible stale results) ")
else
@out.puts("")
end
end end
end end