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)
get = org.apache.hadoop.hbase.client.Get.new(row.to_s.to_java_bytes)
maxlength = -1
count = 0
@converters.clear()
# Normalize args
@ -370,6 +371,10 @@ EOF
result = @table.get(get)
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.
res = {}
result.listCells.each do |c|
@ -389,7 +394,7 @@ EOF
end
# 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
#----------------------------------------------------------------------------------------------
@ -509,6 +514,7 @@ EOF
while iter.hasNext
row = iter.next
key = org.apache.hadoop.hbase.util.Bytes::toStringBinary(row.getRow)
is_stale |= row.isStale
row.listCells.each do |c|
family = org.apache.hadoop.hbase.util.Bytes::toStringBinary(c.getFamilyArray,
@ -536,7 +542,7 @@ EOF
end
scanner.close()
return ((block_given?) ? count : res)
return ((block_given?) ? [count, is_stale] : res)
end
# Apply OperationAttributes to puts/scans/gets

View File

@ -84,11 +84,11 @@ EOF
now = Time.now
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 ])
end
formatter.footer(now)
formatter.footer(now, count, is_stale)
end
end
end

View File

@ -109,12 +109,11 @@ EOF
scan = table._hash_to_scan(args)
#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 ])
end
formatter.footer(now, count)
formatter.footer(now, count, is_stale)
# if scan metrics were enabled, print them after the results
if (scan != nil && scan.isScanMetricsEnabled())
formatter.scan_metrics(scan.getScanMetrics(), args["METRICS"])

View File

@ -177,11 +177,16 @@ module Shell
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
row_count ||= @row_count
# 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