MCPcopy Create free account
hub / github.com/apache/solr / initTlogDir

Method initTlogDir

solr/core/src/java/org/apache/solr/update/UpdateLog.java:548–627  ·  view source on GitHub ↗

Based on #dataDir (whose initialization must be complete before this method is called), this method is responsible for, in order: resolving the tlog dir (in an implementation-dependent way) clearing any existing entries (if applicable) by calling {@link #maybeClearLog(SolrC

(SolrCore core)

Source from the content-addressed store, hash-verified

546 * resolving the tlog dir, and before creating any (or handling any existing) tlog files.
547 */
548 protected void initTlogDir(SolrCore core) {
549 Path instancePath = core.getInstancePath();
550
551 Path dataDirPath = Path.of(dataDir);
552
553 // intentionally use assert side-effect assignment here. `Path.startsWith()` fails if the
554 // argument is a different class, which is the case for `SolrCore.getInstancePath()`,
555 // strictly in tests (lucene test-framework `FilterPath`).
556 assert (instancePath = Path.of(instancePath.toUri())).getClass()
557 == (dataDirPath = Path.of(dataDirPath.toUri())).getClass();
558
559 tlogDir = ulogToTlogDir(core.getName(), dataDirPath, instancePath, core.getDataDir());
560
561 maybeClearLog(core);
562
563 // usage of tlog dir almost entirely bypasses `Directory` API; we only need to do this so that
564 // we can remove the tlog dir via `DirectoryFactory.remove()`, which understands how to delete
565 // in filesystem-specific ways.
566 DirectoryFactory df = core.getDirectoryFactory();
567 Directory d;
568 try {
569 d =
570 df.get(
571 tlogDir.toAbsolutePath().toString(),
572 DirectoryFactory.DirContext.DEFAULT,
573 DirectoryFactory.LOCK_TYPE_NONE);
574 this.releaseTlogDir = () -> df.release(d);
575 } catch (IOException e) {
576 throw new UncheckedIOException(e);
577 }
578
579 try {
580 Files.createDirectories(tlogDir);
581 } catch (IOException e) {
582 throw new SolrException(ErrorCode.SERVER_ERROR, "Could not set up tlogs", e);
583 }
584 tlogFiles = getLogList(tlogDir);
585 id = getLastLogId() + 1; // add 1 since we will create a new log for the next update
586
587 if (debug) {
588 log.debug(
589 "UpdateHandler init: tlogDir={}, existing tlogs={}, next id={}",
590 tlogDir,
591 Arrays.asList(tlogFiles),
592 id);
593 }
594
595 final String prefix = BUFFER_TLOG_NAME + '.';
596 try (Stream<Path> bufferedTLogs = Files.walk(tlogDir, 1)) {
597 existOldBufferLog =
598 bufferedTLogs.anyMatch(path -> path.getFileName().toString().startsWith(prefix));
599 } catch (IOException e) {
600 // Existance of buffered t-logs indicates previous recovery failed and lets us skip peer sync
601 // as an optimization. Failing to read them is non-fatal and almost not even worth logging
602 // about
603 log.debug(
604 "Could not read {} directory searching for buffered transaction log files.", tlogDir, e);
605 existOldBufferLog = false;

Callers 1

initMethod · 0.95

Calls 15

ulogToTlogDirMethod · 0.95
maybeClearLogMethod · 0.95
getMethod · 0.95
releaseMethod · 0.95
getLogListMethod · 0.95
getLastLogIdMethod · 0.95
newTransactionLogMethod · 0.95
addOldLogMethod · 0.95
deleteFileMethod · 0.95
createDirectoriesMethod · 0.80
debugMethod · 0.80
getFileNameMethod · 0.80

Tested by

no test coverage detected