AMashenkov commented on a change in pull request #9423:
URL: https://github.com/apache/ignite/pull/9423#discussion_r711978560
##########
File path:
modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/stat/IgniteStatisticsManagerImpl.java
##########
@@ -297,78 +332,104 @@ public IgniteStatisticsConfigurationManager
statisticConfiguration() {
/** {@inheritDoc} */
@Override public StatisticsUsageState usageState() {
- return usageState.getOrDefault(DEFAULT_STATISTICS_USAGE_STATE);
+ return (lastUsageState == null) ? DEFAULT_STATISTICS_USAGE_STATE :
lastUsageState;
}
/** {@inheritDoc} */
@Override public void onRowUpdated(String schemaName, String objName, int
partId, byte[] keyBytes) {
- try {
- if (statCfgMgr.config(new StatisticsKey(schemaName, objName)) !=
null)
- statsRepos.addRowsModified(new StatisticsKey(schemaName,
objName), partId, keyBytes);
- }
- catch (IgniteCheckedException e) {
- if (log.isInfoEnabled())
- log.info(String.format("Error while obsolescence key in %s.%s
due to %s", schemaName, objName,
- e.getMessage()));
- }
+ statsRepos.addRowsModified(new StatisticsKey(schemaName, objName),
partId, keyBytes);
}
/**
* Save dirty obsolescence info to local metastore. Check if statistics
need to be refreshed and schedule it.
+ *
+ * 1) Get all dirty partition statistics.
+ * 2) Make separate tasks for each key to avoid saving obsolescence info
for removed partition (race).
+ * 3) Check if partition should be recollected and add it to list in its
tables task.
+ * 4) Submit tasks. Actually obsolescence info will be stored during task
processing.
*/
public synchronized void processObsolescence() {
- Map<StatisticsKey, IntMap<ObjectPartitionStatisticsObsolescence>>
dirty = statsRepos.saveObsolescenceInfo();
+ StatisticsUsageState state = usageState();
- Map<StatisticsKey, List<Integer>> tasks =
calculateObsolescenceRefreshTasks(dirty);
-
- if (!F.isEmpty(tasks))
- if (log.isTraceEnabled())
- log.trace(String.format("Refreshing statistics for %d
targets", tasks.size()));
+ if (state != ON || ctx.isStopping()) {
+ if (log.isDebugEnabled())
+ log.debug("Skipping obsolescence processing.");
- for (Map.Entry<StatisticsKey, List<Integer>> objTask :
tasks.entrySet()) {
- GridH2Table tbl = schemaMgr.dataTable(objTask.getKey().schema(),
objTask.getKey().obj());
+ return;
+ }
- if (tbl == null) {
- if (log.isDebugEnabled())
- log.debug(String.format("Got obsolescence statistics for
unknown table %s", objTask.getKey()));
+ if (log.isTraceEnabled())
+ log.trace("Process statistics obsolescence started.");
- continue;
- }
+ Map<StatisticsKey, IntMap<ObjectPartitionStatisticsObsolescence>>
dirty = statsRepos.getDirtyObsolescenceInfo();
- StatisticsObjectConfiguration objCfg;
- try {
- objCfg = statCfgMgr.config(objTask.getKey());
- } catch (IgniteCheckedException e) {
- log.warning("Unable to load statistics object configuration
from global metastore", e);
- continue;
- }
+ if (F.isEmpty(dirty)) {
+ if (log.isTraceEnabled())
+ log.trace("No dirty obsolescence info found. Finish
obsolescence processing.");
- if (objCfg == null) {
- if (log.isDebugEnabled())
- log.debug(String.format("Got obsolescence statistics for
unknown configuration %s", objTask.getKey()));
+ return;
+ }
+ else {
+ if (log.isTraceEnabled())
+ log.trace(String.format("Scheduling obsolescence savings for
%d targets", dirty.size()));
+ }
- continue;
- }
+ Map<StatisticsObjectConfiguration, List<Integer>> tasks =
calculateObsolescenceRefreshTasks(dirty);
- GridCacheContext cctx = tbl.cacheContext();
+ for (Map.Entry<StatisticsObjectConfiguration, List<Integer>> objTask :
tasks.entrySet()) {
+ StatisticsKey key = objTask.getKey().key();
+ GridH2Table tbl = schemaMgr.dataTable(key.schema(), key.obj());
- Set<Integer> parts = cctx.affinity().primaryPartitions(
- cctx.localNodeId(), cctx.affinity().affinityTopologyVersion());
+ if (tbl == null) {
+ // Table can be removed earlier, but not already processed. Or
somethink goes wrong. Try to reschedule.
+ if (log.isDebugEnabled())
+ log.debug(String.format("Got obsolescence statistics for
unknown table %s", objTask.getKey()));
+ }
- statCfgMgr.gatherLocalStatistics(objCfg, tbl, parts, new
HashSet<>(objTask.getValue()), null);
+ statProc.updateKeyAsync(true, tbl, objTask.getKey(), new
HashSet<>(objTask.getValue()),
+ null);
+// if (objTask.getValue().isEmpty()) {
+// // Just save or totally remove obsolescence info, no
additional operations needed.
+// statProc.updateKeyAsync(true, tbl, objTask.getKey(),
Collections.emptySet(), null);
+// }
+// else {
+// // Schedule full gathering.
+// GridCacheContext<?, ?> cctx = (tbl == null) ? null :
tbl.cacheContext();
+//
+// AffinityTopologyVersion topVer = null;
+//
+// if (!cctx.gate().enterIfNotStopped())
+// continue;
+//
+// try {
+// topVer = cctx.affinity().affinityTopologyVersion();
+// cctx.affinity().affinityReadyFuture(topVer).get();
+// }
+// catch (IgniteCheckedException e) {
+// log.warning("Unable to get topology ready.", e);
+// }
+// finally {
+// cctx.gate().leave();
+// }
+//
+// statProc.updateKeyAsync(true, tbl, objTask.getKey(), new
HashSet<>(objTask.getValue()),
+// topVer);
+//
+// }
Review comment:
Commented code
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]