Skip to content

Commit

Permalink
Adding more logging and status information to the Reindex Process
Browse files Browse the repository at this point in the history
  • Loading branch information
jcastro-dotcms committed Dec 11, 2024
1 parent 8bf901e commit 547b57a
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ public boolean fullReindexSwitchover(Connection conn, final boolean forceSwitch)
< Config.getLongProperty("REINDEX_THREAD_MINIMUM_RUNTIME_IN_SEC", 30) * 1000) {
if (reindexTimeElapsed().isPresent()) {
Logger.info(this.getClass(),
"Reindex has been running only " + reindexTimeElapsed().get()
"Reindex has been running only " + reindexTimeElapsed().orElse("- No value present -")
+ ". Letting the reindex settle.");
} else {
Logger.info(this.getClass(), "Reindex Time Elapsed not set.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3784,15 +3784,19 @@ public void refresh(Contentlet contentlet) throws DotReindexStateException,
public void refreshAllContent() throws DotReindexStateException {
try {
if (indexAPI.isInFullReindex()) {
Logger.info(this, "=======> Full reindex already in progress, skipping refresh all content");
return;
}
// we prepare the new index and aliases to point both old and new
Logger.info(this, "=======> Preparing the new index and aliases to point both old and new");
indexAPI.fullReindexStart();

// delete failing records
Logger.info(this, "=======> Deleting failing records");
reindexQueueAPI.deleteFailedRecords();

// new records to index
Logger.info(this, "=======> Adding all records to reindex queue");
reindexQueueAPI.addAllToReindexQueue();

} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,7 @@ public Response startReindex(@Context final HttpServletRequest request, @Context
APILocator.getContentletAPI().refresh(type);
}
else {
Logger.info(this, "=======> Refreshing ALL contents in dotCMS");
APILocator.getContentletAPI().refreshAllContent();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,13 @@ protected void addAllToReindexQueue() throws DotDataException {
+ " from contentlet_version_info where identifier is not null";
dc.setSQL(sql);
dc.loadResult();

dc = new DotConnect();
dc.setSQL("SELECT count(*) as count from dist_reindex_journal");
final List<Map<String, Object>> count = dc.loadObjectResults();
if (!count.isEmpty()) {
Logger.info(this, String.format("=======> After adding all from the contentlet_version_info table, there are %s records in the table", count.get(0).getOrDefault("count", "- NO VALUE -")));
}
} catch (Exception e) {
throw new DotDataException(e.getMessage(), e);
}
Expand Down Expand Up @@ -341,13 +348,25 @@ private void loadUpLocalQueue() throws DotDataException {
db.addParam(priorityLevel);
db.addParam(lastIdIndexed);

for (Map<String, Object> map : db.loadObjectResults()) {
Logger.info(this, String.format("Loading %d records from the reindex journal with reindexingServers = [ %s], myIndex = [ %s ], priorityLevel = [ %s ], lastIdIndexed = [ %s ]",
REINDEX_RECORDS_TO_FETCH, reindexingServers, myIndex, priorityLevel, lastIdIndexed));
final DotConnect dc2 = new DotConnect();
dc2.setSQL("SELECT count(*) as count from dist_reindex_journal");
final List<Map<String, Object>> count = dc2.loadObjectResults();
if (!count.isEmpty()) {
Logger.info(this, String.format("=======> Total records in reindex journal: %s", count.get(0).getOrDefault("count", "- NO VALUE -")));
}

final List<Map<String, Object>> results = db.loadObjectResults();
Logger.info(this, String.format("=======> Loaded %d records from the reindex journal", results.size()));
for (Map<String, Object> map : results) {
final ReindexEntry entry = mapToReindexEntry(map);
lastIdIndexed = entry.getId();
queue.add(entry);
}

if (queue.isEmpty()) {
Logger.info(this, "=======> The reindex queue is empty!");
lastIdIndexed = 0;
}
}
Expand Down

0 comments on commit 547b57a

Please sign in to comment.