@@ -52,6 +52,9 @@ public class GenerateQueryWorkLoad extends QueryWorkLoad {
5252
5353 private static final Logger LOGGER = LoggerFactory .getLogger (GenerateQueryWorkLoad .class );
5454
55+ private static volatile List <DeviceSchema > cachedQueryDeviceSchemaListTypeAllow = null ;
56+ private static volatile List <DeviceSchema > cachedQueryDeviceSchemaListTypeFiltered = null ;
57+
5558 private final Random queryDeviceRandom ;
5659 private final Random querySensorRandom ;
5760 private static final long timeStampConst =
@@ -73,22 +76,48 @@ public GenerateQueryWorkLoad(int id) {
7376
7477 @ Override
7578 public PreciseQuery getPreciseQuery () throws WorkloadException {
76- List <DeviceSchema > queryDevices = getQueryDeviceSchemaList (true );
79+ List <DeviceSchema > queryDevices = getQueryDeviceSchema (true , config . isENABLE_FIXED_QUERY () );
7780 long timestamp = getQueryStartTimestamp (Operation .PRECISE_QUERY );
7881 return new PreciseQuery (queryDevices , timestamp );
7982 }
8083
84+ public List <DeviceSchema > getQueryDeviceSchema (boolean typeAllow , boolean fixedSQl )
85+ throws WorkloadException {
86+ if (!fixedSQl ) {
87+ return getQueryDeviceSchemaList (typeAllow );
88+ }
89+ if (typeAllow ) {
90+ if (cachedQueryDeviceSchemaListTypeAllow == null ) {
91+ synchronized (GenerateQueryWorkLoad .class ) {
92+ if (cachedQueryDeviceSchemaListTypeAllow == null ) {
93+ cachedQueryDeviceSchemaListTypeAllow = getQueryDeviceSchemaList (typeAllow );
94+ }
95+ }
96+ }
97+ return cachedQueryDeviceSchemaListTypeAllow ;
98+ } else {
99+ if (cachedQueryDeviceSchemaListTypeFiltered == null ) {
100+ synchronized (GenerateQueryWorkLoad .class ) {
101+ if (cachedQueryDeviceSchemaListTypeFiltered == null ) {
102+ cachedQueryDeviceSchemaListTypeFiltered = getQueryDeviceSchemaList (typeAllow );
103+ }
104+ }
105+ }
106+ return cachedQueryDeviceSchemaListTypeFiltered ;
107+ }
108+ }
109+
81110 @ Override
82111 public RangeQuery getRangeQuery () throws WorkloadException {
83- List <DeviceSchema > queryDevices = getQueryDeviceSchemaList (true );
112+ List <DeviceSchema > queryDevices = getQueryDeviceSchema (true , config . isENABLE_FIXED_QUERY () );
84113 long startTimestamp = getQueryStartTimestamp (Operation .RANGE_QUERY );
85114 long endTimestamp = startTimestamp + config .getQUERY_INTERVAL ();
86115 return new RangeQuery (queryDevices , startTimestamp , endTimestamp );
87116 }
88117
89118 @ Override
90119 public ValueRangeQuery getValueRangeQuery () throws WorkloadException {
91- List <DeviceSchema > queryDevices = getQueryDeviceSchemaList (false );
120+ List <DeviceSchema > queryDevices = getQueryDeviceSchema (false , config . isENABLE_FIXED_QUERY () );
92121 long startTimestamp = getQueryStartTimestamp (Operation .VALUE_RANGE_QUERY );
93122 long endTimestamp = startTimestamp + config .getQUERY_INTERVAL ();
94123 return new ValueRangeQuery (
@@ -98,7 +127,8 @@ public ValueRangeQuery getValueRangeQuery() throws WorkloadException {
98127 @ Override
99128 public AggRangeQuery getAggRangeQuery () throws WorkloadException {
100129 List <DeviceSchema > queryDevices =
101- getQueryDeviceSchemaList (config .getQUERY_AGGREGATE_FUN ().startsWith ("count" ));
130+ getQueryDeviceSchema (
131+ config .getQUERY_AGGREGATE_FUN ().startsWith ("count" ), config .isENABLE_FIXED_QUERY ());
102132 long startTimestamp = getQueryStartTimestamp (Operation .AGG_RANGE_QUERY );
103133 long endTimestamp = startTimestamp + config .getQUERY_INTERVAL ();
104134 return new AggRangeQuery (
@@ -107,14 +137,14 @@ public AggRangeQuery getAggRangeQuery() throws WorkloadException {
107137
108138 @ Override
109139 public AggValueQuery getAggValueQuery () throws WorkloadException {
110- List <DeviceSchema > queryDevices = getQueryDeviceSchemaList (false );
140+ List <DeviceSchema > queryDevices = getQueryDeviceSchema (false , config . isENABLE_FIXED_QUERY () );
111141 return new AggValueQuery (
112142 queryDevices , config .getQUERY_AGGREGATE_FUN (), config .getQUERY_LOWER_VALUE ());
113143 }
114144
115145 @ Override
116146 public AggRangeValueQuery getAggRangeValueQuery () throws WorkloadException {
117- List <DeviceSchema > queryDevices = getQueryDeviceSchemaList (false );
147+ List <DeviceSchema > queryDevices = getQueryDeviceSchema (false , config . isENABLE_FIXED_QUERY () );
118148 long startTimestamp = getQueryStartTimestamp (Operation .AGG_RANGE_VALUE_QUERY );
119149 long endTimestamp = startTimestamp + config .getQUERY_INTERVAL ();
120150 return new AggRangeValueQuery (
@@ -136,7 +166,8 @@ public GroupByQuery getGroupByQuery() throws WorkloadException {
136166 && config .getANOTHER_DBConfig ().getDB_SWITCH () == DBSwitch .DB_INFLUX_2 )) {
137167 typeAllow = false ;
138168 }
139- List <DeviceSchema > queryDevices = getQueryDeviceSchemaList (typeAllow );
169+ List <DeviceSchema > queryDevices =
170+ getQueryDeviceSchema (typeAllow , config .isENABLE_FIXED_QUERY ());
140171 long startTimestamp = getQueryStartTimestamp (Operation .GROUP_BY_QUERY );
141172 long endTimestamp = startTimestamp + config .getQUERY_INTERVAL ();
142173 return new GroupByQuery (
@@ -149,7 +180,7 @@ public GroupByQuery getGroupByQuery() throws WorkloadException {
149180
150181 @ Override
151182 public LatestPointQuery getLatestPointQuery () throws WorkloadException {
152- List <DeviceSchema > queryDevices = getQueryDeviceSchemaList (true );
183+ List <DeviceSchema > queryDevices = getQueryDeviceSchema (true , config . isENABLE_FIXED_QUERY () );
153184 long startTimestamp = getQueryStartTimestamp (Operation .LATEST_POINT_QUERY );
154185 long endTimestamp = startTimestamp + config .getQUERY_INTERVAL ();
155186 return new LatestPointQuery (
@@ -188,7 +219,10 @@ private long getQueryStartTimestamp(Operation operation) {
188219 }
189220 }
190221 long currentQueryLoop = operationLoops .get (operation ).getAndIncrement ();
191- long timestampOffset = currentQueryLoop * config .getSTEP_SIZE () * config .getPOINT_STEP ();
222+ long timestampOffset = 0 ;
223+ if (!config .isENABLE_FIXED_QUERY ()) {
224+ timestampOffset = currentQueryLoop * config .getSTEP_SIZE () * config .getPOINT_STEP ();
225+ }
192226 return Constants .START_TIMESTAMP * timeStampConst + timestampOffset ;
193227 }
194228
0 commit comments