ss: add a wrapper for the state system delete files
[deliverable/tracecompass.git] / statesystem / org.eclipse.tracecompass.statesystem.core / src / org / eclipse / tracecompass / internal / statesystem / core / StateSystem.java
CommitLineData
a52fde77 1/*******************************************************************************
c44f0a0c 2 * Copyright (c) 2012, 2016 Ericsson
a52fde77
AM
3 * Copyright (c) 2010, 2011 École Polytechnique de Montréal
4 * Copyright (c) 2010, 2011 Alexandre Montplaisir <alexandre.montplaisir@gmail.com>
5df842b3 5 *
a52fde77
AM
6 * All rights reserved. This program and the accompanying materials are
7 * made available under the terms of the Eclipse Public License v1.0 which
8 * accompanies this distribution, and is available at
9 * http://www.eclipse.org/legal/epl-v10.html
5df842b3 10 *
e13bd4cd
PT
11 * Contributors:
12 * Alexandre Montplaisir - Initial API and implementation
13 * Patrick Tasse - Add message to exceptions
a52fde77
AM
14 *******************************************************************************/
15
e894a508 16package org.eclipse.tracecompass.internal.statesystem.core;
a52fde77 17
8d1346f0
AM
18import java.io.File;
19import java.io.IOException;
8d1346f0 20import java.util.ArrayList;
c44f0a0c 21import java.util.Arrays;
f94a0bac 22import java.util.LinkedList;
a52fde77 23import java.util.List;
16576a7e 24import java.util.concurrent.CountDownLatch;
9287b6a2 25import java.util.concurrent.TimeUnit;
b2648641 26import java.util.logging.Logger;
a52fde77 27
2e21b6d8 28import org.eclipse.jdt.annotation.NonNull;
df2597e0 29import org.eclipse.jdt.annotation.Nullable;
b2648641 30import org.eclipse.tracecompass.common.core.log.TraceCompassLog;
e894a508
AM
31import org.eclipse.tracecompass.statesystem.core.ITmfStateSystemBuilder;
32import org.eclipse.tracecompass.statesystem.core.backend.IStateHistoryBackend;
33import org.eclipse.tracecompass.statesystem.core.exceptions.AttributeNotFoundException;
34import org.eclipse.tracecompass.statesystem.core.exceptions.StateSystemDisposedException;
35import org.eclipse.tracecompass.statesystem.core.exceptions.StateValueTypeException;
36import org.eclipse.tracecompass.statesystem.core.exceptions.TimeRangeException;
37import org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval;
e894a508 38import org.eclipse.tracecompass.statesystem.core.statevalue.ITmfStateValue;
e894a508 39import org.eclipse.tracecompass.statesystem.core.statevalue.ITmfStateValue.Type;
1dd75589 40import org.eclipse.tracecompass.statesystem.core.statevalue.TmfStateValue;
a52fde77 41
aa315d8b
PT
42import com.google.common.collect.ImmutableCollection.Builder;
43import com.google.common.collect.ImmutableSet;
44
a52fde77 45/**
8d1346f0
AM
46 * This is the core class of the Generic State System. It contains all the
47 * methods to build and query a state history. It's exposed externally through
48 * the IStateSystemQuerier and IStateSystemBuilder interfaces, depending if the
49 * user needs read-only access or read-write access.
5df842b3 50 *
8d1346f0
AM
51 * When building, DON'T FORGET to call .closeHistory() when you are done
52 * inserting intervals, or the storage backend will have no way of knowing it
53 * can close and write itself to disk, and its thread will keep running.
5df842b3 54 *
a52fde77 55 * @author alexmont
5df842b3 56 *
a52fde77 57 */
f1f86dfb 58public class StateSystem implements ITmfStateSystemBuilder {
a52fde77 59
aa315d8b
PT
60 private static final String PARENT = ".."; //$NON-NLS-1$
61 private static final String WILDCARD = "*"; //$NON-NLS-1$
62
b2648641
GB
63 private static final Logger LOGGER = TraceCompassLog.getLogger(StateSystem.class);
64
a52fde77 65 /* References to the inner structures */
8d1346f0
AM
66 private final AttributeTree attributeTree;
67 private final TransientState transState;
68 private final IStateHistoryBackend backend;
a52fde77 69
16576a7e
AM
70 /* Latch tracking if the state history is done building or not */
71 private final CountDownLatch finishedLatch = new CountDownLatch(1);
72
1a4205d9 73 private boolean buildCancelled = false;
96345c5a 74 private boolean isDisposed = false;
1a4205d9 75
f9a76cac
AM
76 /**
77 * New-file constructor. For when you build a state system with a new file,
78 * or if the back-end does not require a file on disk.
79 *
80 * @param backend
81 * Back-end plugin to use
82 */
b2f62cb5 83 public StateSystem(@NonNull IStateHistoryBackend backend) {
f9a76cac
AM
84 this.backend = backend;
85 this.transState = new TransientState(backend);
86 this.attributeTree = new AttributeTree(this);
87 }
88
a52fde77 89 /**
8d1346f0
AM
90 * General constructor
91 *
92 * @param backend
f9a76cac 93 * The "state history storage" back-end to use.
8d1346f0
AM
94 * @param newFile
95 * Put true if this is a new history started from scratch. It is
96 * used to tell the state system where to get its attribute tree.
97 * @throws IOException
98 * If there was a problem creating the new history file
a52fde77 99 */
b2f62cb5 100 public StateSystem(@NonNull IStateHistoryBackend backend, boolean newFile)
8d1346f0
AM
101 throws IOException {
102 this.backend = backend;
103 this.transState = new TransientState(backend);
a52fde77 104
8d1346f0
AM
105 if (newFile) {
106 attributeTree = new AttributeTree(this);
107 } else {
108 /* We're opening an existing file */
109 this.attributeTree = new AttributeTree(this, backend.supplyAttributeTreeReader());
110 transState.setInactive();
16576a7e
AM
111 finishedLatch.countDown(); /* The history is already built */
112 }
113 }
114
84a9548a
AM
115 @Override
116 public String getSSID() {
b2f62cb5 117 return backend.getSSID();
84a9548a
AM
118 }
119
16576a7e 120 @Override
2002c638
AM
121 public boolean isCancelled() {
122 return buildCancelled;
123 }
124
125 @Override
126 public void waitUntilBuilt() {
16576a7e
AM
127 try {
128 finishedLatch.await();
129 } catch (InterruptedException e) {
130 e.printStackTrace();
8d1346f0 131 }
1a4205d9
AM
132 }
133
9287b6a2
AM
134 @Override
135 public boolean waitUntilBuilt(long timeout) {
136 boolean ret = false;
137 try {
138 ret = finishedLatch.await(timeout, TimeUnit.MILLISECONDS);
139 } catch (InterruptedException e) {
140 e.printStackTrace();
141 }
142 return ret;
143 }
144
1a4205d9
AM
145 @Override
146 public synchronized void dispose() {
96345c5a 147 isDisposed = true;
1a4205d9
AM
148 if (transState.isActive()) {
149 transState.setInactive();
150 buildCancelled = true;
151 }
152 backend.dispose();
a52fde77
AM
153 }
154
8d1346f0
AM
155 //--------------------------------------------------------------------------
156 // General methods related to the attribute tree
157 //--------------------------------------------------------------------------
158
339d27b4
AM
159 /**
160 * Get the attribute tree associated with this state system. This should be
161 * the only way of accessing it (and if subclasses want to point to a
162 * different attribute tree than their own, they should only need to
163 * override this).
164 *
165 * @return The attribute tree
166 */
167 public AttributeTree getAttributeTree() {
168 return attributeTree;
169 }
170
8d1346f0
AM
171 /**
172 * Method used by the attribute tree when creating new attributes, to keep
173 * the attribute count in the transient state in sync.
174 */
bcec0116 175 public void addEmptyAttribute() {
8d1346f0
AM
176 transState.addEmptyEntry();
177 }
178
179 @Override
4623f57f 180 public int getNbAttributes() {
339d27b4 181 return getAttributeTree().getNbAttributes();
4623f57f
AM
182 }
183
8d1346f0
AM
184 @Override
185 public String getAttributeName(int attributeQuark) {
339d27b4 186 return getAttributeTree().getAttributeName(attributeQuark);
8d1346f0
AM
187 }
188
189 @Override
190 public String getFullAttributePath(int attributeQuark) {
339d27b4 191 return getAttributeTree().getFullAttributeName(attributeQuark);
8d1346f0
AM
192 }
193
34638411
AM
194 @Override
195 public String[] getFullAttributePathArray(int attributeQuark) {
196 return getAttributeTree().getFullAttributePathArray(attributeQuark);
197 }
198
8d1346f0
AM
199 //--------------------------------------------------------------------------
200 // Methods related to the storage backend
201 //--------------------------------------------------------------------------
a52fde77 202
8d1346f0
AM
203 @Override
204 public long getStartTime() {
205 return backend.getStartTime();
206 }
207
208 @Override
209 public long getCurrentEndTime() {
210 return backend.getEndTime();
211 }
212
213 @Override
214 public void closeHistory(long endTime) throws TimeRangeException {
215 File attributeTreeFile;
216 long attributeTreeFilePos;
217 long realEndTime = endTime;
218
219 if (realEndTime < backend.getEndTime()) {
220 /*
221 * This can happen (empty nodes pushing the border further, etc.)
222 * but shouldn't be too big of a deal.
223 */
224 realEndTime = backend.getEndTime();
225 }
226 transState.closeTransientState(realEndTime);
227 backend.finishedBuilding(realEndTime);
228
229 attributeTreeFile = backend.supplyAttributeTreeWriterFile();
230 attributeTreeFilePos = backend.supplyAttributeTreeWriterFilePosition();
231 if (attributeTreeFile != null) {
232 /*
233 * If null was returned, we simply won't save the attribute tree,
234 * too bad!
235 */
339d27b4 236 getAttributeTree().writeSelf(attributeTreeFile, attributeTreeFilePos);
8d1346f0 237 }
16576a7e 238 finishedLatch.countDown(); /* Mark the history as finished building */
8d1346f0
AM
239 }
240
241 //--------------------------------------------------------------------------
242 // Quark-retrieving methods
243 //--------------------------------------------------------------------------
244
245 @Override
a52fde77
AM
246 public int getQuarkAbsolute(String... attribute)
247 throws AttributeNotFoundException {
c44f0a0c
PT
248 int quark = getAttributeTree().getQuarkDontAdd(ROOT_ATTRIBUTE, attribute);
249 if (quark == INVALID_ATTRIBUTE) {
250 throw new AttributeNotFoundException(getSSID() + " Path:" + Arrays.toString(attribute)); //$NON-NLS-1$
251 }
252 return quark;
253 }
254
255 @Override
256 public int optQuarkAbsolute(String... attribute) {
257 return getAttributeTree().getQuarkDontAdd(ROOT_ATTRIBUTE, attribute);
a52fde77
AM
258 }
259
8d1346f0 260 @Override
a52fde77 261 public int getQuarkAbsoluteAndAdd(String... attribute) {
c44f0a0c 262 return getAttributeTree().getQuarkAndAdd(ROOT_ATTRIBUTE, attribute);
a52fde77
AM
263 }
264
8d1346f0 265 @Override
a52fde77
AM
266 public int getQuarkRelative(int startingNodeQuark, String... subPath)
267 throws AttributeNotFoundException {
c44f0a0c
PT
268 int quark = getAttributeTree().getQuarkDontAdd(startingNodeQuark, subPath);
269 if (quark == INVALID_ATTRIBUTE) {
270 throw new AttributeNotFoundException(getSSID() + " Quark:" + startingNodeQuark + ", SubPath:" + Arrays.toString(subPath)); //$NON-NLS-1$ //$NON-NLS-2$
271 }
272 return quark;
273 }
274
275 @Override
276 public int optQuarkRelative(int startingNodeQuark, String... subPath) {
339d27b4 277 return getAttributeTree().getQuarkDontAdd(startingNodeQuark, subPath);
a52fde77
AM
278 }
279
8d1346f0 280 @Override
a52fde77 281 public int getQuarkRelativeAndAdd(int startingNodeQuark, String... subPath) {
339d27b4 282 return getAttributeTree().getQuarkAndAdd(startingNodeQuark, subPath);
a52fde77
AM
283 }
284
8d1346f0 285 @Override
ed48dc75 286 public List<@NonNull Integer> getSubAttributes(int quark, boolean recursive) {
339d27b4 287 return getAttributeTree().getSubAttributes(quark, recursive);
0a9de3d2
AM
288 }
289
5206c858 290 @Override
ed48dc75 291 public List<@NonNull Integer> getSubAttributes(int quark, boolean recursive, String pattern) {
5206c858 292 List<Integer> all = getSubAttributes(quark, recursive);
aa315d8b 293 List<@NonNull Integer> ret = new LinkedList<>();
5206c858
AM
294 for (Integer attQuark : all) {
295 String name = getAttributeName(attQuark.intValue());
296 if (name.matches(pattern)) {
297 ret.add(attQuark);
298 }
299 }
300 return ret;
301 }
302
0fdd2c45
FG
303 @Override
304 public int getParentAttributeQuark(int quark) {
305 return getAttributeTree().getParentAttributeQuark(quark);
306 }
307
8d1346f0 308 @Override
df2597e0 309 public List<@NonNull Integer> getQuarks(String... pattern) {
aa315d8b
PT
310 return getQuarks(ROOT_ATTRIBUTE, pattern);
311 }
f94a0bac 312
aa315d8b
PT
313 @Override
314 public List<@NonNull Integer> getQuarks(int startingNodeQuark, String... pattern) {
315 Builder<@NonNull Integer> builder = ImmutableSet.builder();
316 if (pattern.length > 0) {
317 getQuarks(builder, startingNodeQuark, Arrays.asList(pattern));
c44f0a0c 318 } else {
aa315d8b 319 builder.add(startingNodeQuark);
f94a0bac 320 }
aa315d8b
PT
321 return builder.build().asList();
322 }
f94a0bac 323
aa315d8b 324 private void getQuarks(Builder<@NonNull Integer> builder, int quark, List<String> pattern) {
ed48dc75
PT
325 String element = pattern.get(0);
326 if (element == null) {
327 return;
328 }
329 List<String> remainder = pattern.subList(1, pattern.size());
330 if (remainder.isEmpty()) {
331 if (element.equals(WILDCARD)) {
332 builder.addAll(getSubAttributes(quark, false));
333 } else if (element.equals(PARENT)){
334 builder.add(getParentAttributeQuark(quark));
335 } else {
336 int subQuark = optQuarkRelative(quark, element);
337 if (subQuark != INVALID_ATTRIBUTE) {
338 builder.add(subQuark);
339 }
f94a0bac 340 }
ed48dc75
PT
341 } else {
342 if (element.equals(WILDCARD)) {
343 for (@NonNull Integer subquark : getSubAttributes(quark, false)) {
344 getQuarks(builder, subquark, remainder);
aa315d8b 345 }
ed48dc75
PT
346 } else if (element.equals(PARENT)){
347 getQuarks(builder, getParentAttributeQuark(quark), remainder);
aa315d8b 348 } else {
ed48dc75
PT
349 int subQuark = optQuarkRelative(quark, element);
350 if (subQuark != INVALID_ATTRIBUTE) {
351 getQuarks(builder, subQuark, remainder);
aa315d8b
PT
352 }
353 }
f94a0bac 354 }
f94a0bac
AM
355 }
356
8d1346f0
AM
357 //--------------------------------------------------------------------------
358 // Methods related to insertions in the history
359 //--------------------------------------------------------------------------
a52fde77 360
8d1346f0 361 @Override
30cdc5e5 362 public void modifyAttribute(long t, @NonNull ITmfStateValue value, int attributeQuark)
ed48dc75 363 throws TimeRangeException, StateValueTypeException {
a52fde77
AM
364 transState.processStateChange(t, value, attributeQuark);
365 }
366
acec47ce 367 @Deprecated
8d1346f0 368 @Override
a52fde77 369 public void incrementAttribute(long t, int attributeQuark)
ed48dc75 370 throws StateValueTypeException, TimeRangeException {
359eeba0
PT
371 ITmfStateValue stateValue = queryOngoingState(attributeQuark);
372 int prevValue = 0;
373 /* if the attribute was previously null, start counting at 0 */
374 if (!stateValue.isNull()) {
375 prevValue = stateValue.unboxInt();
280bbdbb 376 }
a52fde77
AM
377 modifyAttribute(t, TmfStateValue.newValueInt(prevValue + 1),
378 attributeQuark);
379 }
380
8d1346f0 381 @Override
30cdc5e5 382 public void pushAttribute(long t, @NonNull ITmfStateValue value, int attributeQuark)
ed48dc75 383 throws TimeRangeException, StateValueTypeException {
0126a8ca 384 int stackDepth;
a52fde77
AM
385 int subAttributeQuark;
386 ITmfStateValue previousSV = transState.getOngoingStateValue(attributeQuark);
387
388 if (previousSV.isNull()) {
389 /*
390 * If the StateValue was null, this means this is the first time we
391 * use this attribute. Leave stackDepth at 0.
392 */
cb42195c 393 stackDepth = 0;
b67a2540 394 } else if (previousSV.getType() == Type.INTEGER) {
a52fde77
AM
395 /* Previous value was an integer, all is good, use it */
396 stackDepth = previousSV.unboxInt();
a52fde77
AM
397 } else {
398 /* Previous state of this attribute was another type? Not good! */
e13bd4cd 399 throw new StateValueTypeException(getSSID() + " Quark:" + attributeQuark + ", Type:" + previousSV.getType() + ", Expected:" + Type.INTEGER); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
90a25ebe
AM
400 }
401
e8251298 402 if (stackDepth >= 100000) {
90a25ebe 403 /*
a0f8fb9b
FW
404 * Limit stackDepth to 100000, to avoid having Attribute Trees grow
405 * out of control due to buggy insertions
90a25ebe 406 */
e13bd4cd 407 String message = " Stack limit reached, not pushing"; //$NON-NLS-1$
ed48dc75 408 throw new IllegalStateException(getSSID() + " Quark:" + attributeQuark + message); //$NON-NLS-1$
a52fde77
AM
409 }
410
411 stackDepth++;
0126a8ca 412 subAttributeQuark = getQuarkRelativeAndAdd(attributeQuark, String.valueOf(stackDepth));
a52fde77 413
5896eb76 414 modifyAttribute(t, TmfStateValue.newValueInt(stackDepth), attributeQuark);
90a25ebe 415 modifyAttribute(t, value, subAttributeQuark);
a52fde77
AM
416 }
417
8d1346f0 418 @Override
5896eb76 419 public ITmfStateValue popAttribute(long t, int attributeQuark)
ed48dc75 420 throws TimeRangeException, StateValueTypeException {
e2eac108 421 /* These are the state values of the stack-attribute itself */
e13bd4cd 422 ITmfStateValue previousSV = transState.getOngoingStateValue(attributeQuark);
a52fde77
AM
423
424 if (previousSV.isNull()) {
e2eac108
AM
425 /*
426 * Trying to pop an empty stack. This often happens at the start of
427 * traces, for example when we see a syscall_exit, without having
428 * the corresponding syscall_entry in the trace. Just ignore
429 * silently.
430 */
5896eb76 431 return null;
90a25ebe 432 }
b67a2540 433 if (previousSV.getType() != Type.INTEGER) {
a52fde77 434 /*
b67a2540
AM
435 * The existing value was not an integer (which is expected for
436 * stack tops), this doesn't look like a valid stack attribute.
a52fde77 437 */
e13bd4cd 438 throw new StateValueTypeException(getSSID() + " Quark:" + attributeQuark + ", Type:" + previousSV.getType() + ", Expected:" + Type.INTEGER); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
a52fde77
AM
439 }
440
0126a8ca 441 int stackDepth = previousSV.unboxInt();
90a25ebe 442
e2eac108 443 if (stackDepth <= 0) {
a52fde77 444 /* This on the other hand should not happen... */
e13bd4cd 445 throw new StateValueTypeException(getSSID() + " Quark:" + attributeQuark + ", Stack depth:" + stackDepth); //$NON-NLS-1$//$NON-NLS-2$
a52fde77
AM
446 }
447
e2eac108 448 /* The attribute should already exist at this point */
ed48dc75
PT
449 int subAttributeQuark;
450 try {
451 subAttributeQuark = getQuarkRelative(attributeQuark, String.valueOf(stackDepth));
452 } catch (AttributeNotFoundException e) {
453 String message = " Stack attribute missing sub-attribute for depth:" + stackDepth; //$NON-NLS-1$
454 throw new IllegalStateException(getSSID() + " Quark:" + attributeQuark + message); //$NON-NLS-1$
455 }
5896eb76 456 ITmfStateValue poppedValue = queryOngoingState(subAttributeQuark);
a52fde77 457
e2eac108
AM
458 /* Update the state value of the stack-attribute */
459 ITmfStateValue nextSV;
a0f8fb9b 460 if (--stackDepth == 0) {
359eeba0 461 /* Store a null state value */
e2eac108
AM
462 nextSV = TmfStateValue.nullValue();
463 } else {
464 nextSV = TmfStateValue.newValueInt(stackDepth);
465 }
466 modifyAttribute(t, nextSV, attributeQuark);
467
468 /* Delete the sub-attribute that contained the user's state value */
a52fde77 469 removeAttribute(t, subAttributeQuark);
e2eac108 470
5896eb76 471 return poppedValue;
a52fde77
AM
472 }
473
8d1346f0 474 @Override
a52fde77 475 public void removeAttribute(long t, int attributeQuark)
ed48dc75 476 throws TimeRangeException {
c66426fd 477 /*
feea3b3c 478 * Nullify our children first, recursively. We pass 'false' because we
c66426fd
AM
479 * handle the recursion ourselves.
480 */
feea3b3c 481 List<Integer> childAttributes = getSubAttributes(attributeQuark, false);
0126a8ca 482 for (int childNodeQuark : childAttributes) {
feea3b3c
AM
483 if (attributeQuark == childNodeQuark) {
484 /* Something went very wrong when building out attribute tree */
485 throw new IllegalStateException();
486 }
a52fde77
AM
487 removeAttribute(t, childNodeQuark);
488 }
489 /* Nullify ourselves */
7e0b2b56 490 try {
feea3b3c 491 transState.processStateChange(t, TmfStateValue.nullValue(), attributeQuark);
7e0b2b56 492 } catch (StateValueTypeException e) {
50678114
AM
493 /*
494 * Will not happen since we're inserting null values only, but poor
495 * compiler has no way of knowing this...
7e0b2b56 496 */
cb42195c 497 throw new IllegalStateException(e);
7e0b2b56 498 }
a52fde77
AM
499 }
500
8d1346f0
AM
501 //--------------------------------------------------------------------------
502 // "Current" query/update methods
503 //--------------------------------------------------------------------------
a52fde77 504
8d1346f0 505 @Override
ed48dc75 506 public ITmfStateValue queryOngoingState(int attributeQuark) {
a52fde77
AM
507 return transState.getOngoingStateValue(attributeQuark);
508 }
509
602c0697 510 @Override
ed48dc75 511 public long getOngoingStartTime(int attribute) {
602c0697
AM
512 return transState.getOngoingStartTime(attribute);
513 }
514
8d1346f0 515 @Override
ed48dc75 516 public void updateOngoingState(ITmfStateValue newValue, int attributeQuark) {
a52fde77
AM
517 transState.changeOngoingStateValue(attributeQuark, newValue);
518 }
519
66866869
AM
520 /**
521 * Modify the whole "ongoing state" (state values + start times). This can
522 * be used when "seeking" a state system to a different point in the trace
523 * (and restoring the known stateInfo at this location). Use with care!
524 *
525 * @param newStateIntervals
526 * The new List of state values to use as ongoing state info
527 */
df2597e0 528 protected void replaceOngoingState(@NonNull List<@NonNull ITmfStateInterval> newStateIntervals) {
66866869 529 transState.replaceOngoingState(newStateIntervals);
a0f8fb9b 530 }
66866869 531
8d1346f0
AM
532 //--------------------------------------------------------------------------
533 // Regular query methods (sent to the back-end)
534 //--------------------------------------------------------------------------
535
536 @Override
537 public synchronized List<ITmfStateInterval> queryFullState(long t)
96345c5a
AM
538 throws TimeRangeException, StateSystemDisposedException {
539 if (isDisposed) {
540 throw new StateSystemDisposedException();
541 }
542
b2648641
GB
543 LOGGER.info(() -> "[StateSystem:FullQueryStart] ssid=" + this.getSSID() + ", ts=" + t); //$NON-NLS-1$//$NON-NLS-2$
544
e62a23a9 545 final int nbAttr = getNbAttributes();
df2597e0 546 List<@Nullable ITmfStateInterval> stateInfo = new ArrayList<>(nbAttr);
8d1346f0
AM
547
548 /* Bring the size of the array to the current number of attributes */
e62a23a9 549 for (int i = 0; i < nbAttr; i++) {
8d1346f0
AM
550 stateInfo.add(null);
551 }
552
8d1346f0
AM
553 /*
554 * If we are currently building the history, also query the "ongoing"
555 * states for stuff that might not yet be written to the history.
556 */
557 if (transState.isActive()) {
558 transState.doQuery(stateInfo, t);
559 }
560
e62a23a9
AM
561 /* Query the storage backend */
562 backend.doQuery(stateInfo, t);
563
8d1346f0
AM
564 /*
565 * We should have previously inserted an interval for every attribute.
8d1346f0 566 */
e62a23a9
AM
567 for (ITmfStateInterval interval : stateInfo) {
568 if (interval == null) {
569 throw new IllegalStateException("Incoherent interval storage"); //$NON-NLS-1$
8d1346f0
AM
570 }
571 }
b2648641 572 LOGGER.info(() -> "[StateSystem:FullQueryEnd]"); //$NON-NLS-1$
8d1346f0 573 return stateInfo;
50678114
AM
574 }
575
8d1346f0
AM
576 @Override
577 public ITmfStateInterval querySingleState(long t, int attributeQuark)
ed48dc75 578 throws TimeRangeException, StateSystemDisposedException {
96345c5a
AM
579 if (isDisposed) {
580 throw new StateSystemDisposedException();
581 }
8d1346f0 582
b2648641
GB
583 LOGGER.info(() -> "[StateSystem:SingleQueryStart] ssid=" + this.getSSID() + ", ts=" + t + ", attribute=" + attributeQuark); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
584
09e6fd9b
AM
585 ITmfStateInterval ret = transState.getIntervalAt(t, attributeQuark);
586 if (ret == null) {
587 /*
588 * The transient state did not have the information, let's look into
589 * the backend next.
590 */
8d1346f0
AM
591 ret = backend.doSingularQuery(t, attributeQuark);
592 }
593
8d1346f0 594 if (ret == null) {
e62a23a9
AM
595 /*
596 * If we did our job correctly, there should be intervals for every
597 * possible attribute, over all the valid time range.
598 */
599 throw new IllegalStateException("Incoherent interval storage"); //$NON-NLS-1$
8d1346f0 600 }
b2648641 601 LOGGER.info(() -> "[StateSystem:SingleQueryEnd]"); //$NON-NLS-1$
8d1346f0
AM
602 return ret;
603 }
604
d4792e92
MK
605 @Override
606 public void removeFiles() {
607 backend.removeFiles();
608 }
609
8d1346f0
AM
610 //--------------------------------------------------------------------------
611 // Debug methods
612 //--------------------------------------------------------------------------
613
614 static void logMissingInterval(int attribute, long timestamp) {
bcec0116 615 Activator.getDefault().logInfo("No data found in history for attribute " + //$NON-NLS-1$
8d1346f0
AM
616 attribute + " at time " + timestamp + //$NON-NLS-1$
617 ", returning dummy interval"); //$NON-NLS-1$
a52fde77 618 }
8d1346f0 619}
This page took 0.127762 seconds and 5 git commands to generate.