@@ -58,7 +58,8 @@ module Aerospike
5858 INFO2_DURABLE_DELETE = Integer ( 1 << 4 )
5959 # Create only. Fail if record already exists.
6060 INFO2_CREATE_ONLY = Integer ( 1 << 5 )
61-
61+ # Treat as long query, but relax read consistency.
62+ INFO2_RELAX_AP_LONG_QUERY = ( 1 << 6 )
6263 # Return a result for every operation.
6364 INFO2_RESPOND_ALL_OPS = Integer ( 1 << 7 )
6465
@@ -195,7 +196,7 @@ def set_read_for_key_only(policy, key)
195196 field_count += 1 if exp_size > 0
196197
197198 size_buffer
198- write_header_read ( policy , INFO1_READ | INFO1_GET_ALL , 0 , field_count , 0 )
199+ write_header_read ( policy , INFO1_READ | INFO1_GET_ALL , 0 , 0 , field_count , 0 )
199200 write_key ( key )
200201 write_filter_exp ( @policy . filter_exp , exp_size )
201202 end_cmd
@@ -220,7 +221,7 @@ def set_read(policy, key, bin_names)
220221 attr |= INFO1_GET_ALL
221222 end
222223
223- write_header_read ( policy , attr , 0 , field_count , bin_names . length )
224+ write_header_read ( policy , attr , 0 , 0 , field_count , bin_names . length )
224225 write_key ( key )
225226 write_filter_exp ( @policy . filter_exp , exp_size )
226227
@@ -269,7 +270,7 @@ def set_operate(policy, key, args)
269270
270271 size_buffer
271272
272- write_header_read_write ( policy , args . read_attr , args . write_attr , field_count , args . operations . length )
273+ write_header_read_write ( policy , args , field_count )
273274 write_key ( key , policy )
274275 write_filter_exp ( policy . filter_exp , exp_size )
275276
@@ -377,7 +378,7 @@ def set_scan(cluster, policy, namespace, set_name, bin_names, node_partitions)
377378 operation_count = bin_names . length
378379 end
379380
380- write_header_read ( policy , read_attr , info_attr , field_count , operation_count )
381+ write_header_read ( policy , read_attr , 0 , info_attr , field_count , operation_count )
381382
382383 if namespace
383384 write_field_string ( namespace , Aerospike ::FieldType ::NAMESPACE )
@@ -591,10 +592,16 @@ def set_query(cluster, policy, statement, background, node_partitions)
591592 write_header_write ( policy , INFO2_WRITE , field_count , operation_count )
592593 else
593594 read_attr = INFO1_READ
595+ write_attr = 0
596+
594597 read_attr |= INFO1_NOBINDATA unless policy . include_bin_data
595- read_attr |= INFO1_SHORT_QUERY if policy . short_query
598+ if policy . short_query || policy . expected_duration == QueryDuration ::SHORT
599+ read_attr |= INFO1_SHORT_QUERY
600+ elsif policy . expected_duration == QueryDuration ::LONG_RELAX_AP
601+ write_attr |= INFO2_RELAX_AP_LONG_QUERY
602+ end
596603 info_attr = INFO3_PARTITION_DONE if is_new
597- write_header_read ( policy , read_attr , info_attr , field_count , operation_count )
604+ write_header_read ( policy , read_attr , write_attr , info_attr , field_count , operation_count )
598605 end
599606
600607
@@ -903,10 +910,14 @@ def write_header_write(policy, write_attr, field_count, operation_count)
903910 end
904911
905912 # Header write for write operations.
906- def write_header_read_write ( policy , read_attr , write_attr , field_count , operation_count )
913+ def write_header_read_write ( policy , args , field_count )
907914 # Set flags.
908915 generation = Integer ( 0 )
916+ ttl = args . has_write ? policy . expiration : policy . read_touch_ttl_percent
917+ read_attr = args . read_attr
918+ write_attr = args . write_attr
909919 info_attr = Integer ( 0 )
920+ operation_count = args . operations . length
910921
911922 case policy . record_exists_action
912923 when Aerospike ::RecordExistsAction ::UPDATE
@@ -942,7 +953,7 @@ def write_header_read_write(policy, read_attr, write_attr, field_count, operatio
942953 @data_buffer . write_byte ( 0 , 12 ) # unused
943954 @data_buffer . write_byte ( 0 , 13 ) # clear the result code
944955 @data_buffer . write_uint32 ( generation , 14 )
945- @data_buffer . write_uint32 ( policy . ttl , 18 )
956+ @data_buffer . write_uint32 ( ttl , 18 )
946957
947958 # Initialize timeout. It will be written later.
948959 @data_buffer . write_byte ( 0 , 22 )
@@ -956,18 +967,19 @@ def write_header_read_write(policy, read_attr, write_attr, field_count, operatio
956967 @data_offset = MSG_TOTAL_HEADER_SIZE
957968 end
958969
959- def write_header_read ( policy , read_attr , info_attr , field_count , operation_count )
970+ def write_header_read ( policy , read_attr , write_attr , info_attr , field_count , operation_count )
960971 read_attr |= INFO1_COMPRESS_RESPONSE if policy . use_compression
961972 #TODO: Add SC Mode
962973
963974 @data_buffer . write_byte ( MSG_REMAINING_HEADER_SIZE , 8 ) # Message header.length.
964975 @data_buffer . write_byte ( read_attr , 9 )
965- @data_buffer . write_byte ( 0 , 10 )
976+ @data_buffer . write_byte ( write_attr , 10 )
966977 @data_buffer . write_byte ( info_attr , 11 )
967978
968- ( 12 ...22 ) . each { |i | @data_buffer . write_byte ( 0 , i ) }
979+ ( 12 ...18 ) . each { |i | @data_buffer . write_byte ( 0 , i ) }
969980
970981 # Initialize timeout. It will be written later.
982+ @data_buffer . write_int32 ( policy . read_touch_ttl_percent , 18 )
971983 @data_buffer . write_byte ( 0 , 22 )
972984 @data_buffer . write_byte ( 0 , 23 )
973985 @data_buffer . write_byte ( 0 , 24 )
@@ -988,9 +1000,10 @@ def write_header_read_header(policy, read_attr, field_count, operation_count)
9881000 @data_buffer . write_byte ( 0 , 10 )
9891001 @data_buffer . write_byte ( info_attr , 11 )
9901002
991- ( 12 ...22 ) . each { |i | @data_buffer . write_byte ( 0 , i ) }
1003+ ( 12 ...18 ) . each { |i | @data_buffer . write_byte ( 0 , i ) }
9921004
9931005 # Initialize timeout. It will be written later.
1006+ @data_buffer . write_int32 ( policy . read_touch_ttl_percent , 18 )
9941007 @data_buffer . write_byte ( 0 , 22 )
9951008 @data_buffer . write_byte ( 0 , 23 )
9961009 @data_buffer . write_byte ( 0 , 24 )
0 commit comments