1
0
Эх сурвалжийг харах

Fix DatabaseRegistry for Windows (#71008)

In DatabaseRegistry we tried to replace file that was still open. This is not a problem under Linux and MacOS but Windows doesn't like it.
It was caught by our CI with reproducible failures when WindowsFS was set up by Lucene.
Now we skip one temp file and use GzipInputStream directly which fixes this problem.

Marking as non-issue since the code was not released yet.

Closes #70977
Closes #71006
Przemko Robakowski 4 жил өмнө
parent
commit
f1feece422

+ 2 - 8
modules/ingest-geoip/src/main/java/org/elasticsearch/ingest/geoip/DatabaseRegistry.java

@@ -259,12 +259,12 @@ public final class DatabaseRegistry implements Closeable {
             bytes -> Files.write(databaseTmpGzFile, bytes, StandardOpenOption.APPEND),
             () -> {
                 LOGGER.debug("decompressing [{}]", databaseTmpGzFile.getFileName());
-                decompress(databaseTmpGzFile, databaseTmpFile);
 
                 Path databaseFile = geoipTmpDirectory.resolve(databaseName);
                 // tarball contains <database_name>.mmdb, LICENSE.txt, COPYRIGHTS.txt and optional README.txt files.
                 // we store mmdb file as is and prepend database name to all other entries to avoid conflicts
-                try (TarInputStream is = new TarInputStream(new BufferedInputStream(Files.newInputStream(databaseTmpFile)))) {
+                try (TarInputStream is =
+                         new TarInputStream(new GZIPInputStream(new BufferedInputStream(Files.newInputStream(databaseTmpGzFile)), 8192))) {
                     TarInputStream.TarEntry entry;
                     while ((entry = is.getNextEntry()) != null) {
                         //there might be ./ entry in tar, we should skip it
@@ -371,12 +371,6 @@ public final class DatabaseRegistry implements Closeable {
         });
     }
 
-    static void decompress(Path source, Path target) throws IOException {
-        try (GZIPInputStream in = new GZIPInputStream(Files.newInputStream(source), 8192)) {
-            Files.copy(in, target, StandardCopyOption.REPLACE_EXISTING);
-        }
-    }
-
     public Set<String> getAvailableDatabases() {
         return Set.copyOf(databases.keySet());
     }

+ 1 - 2
modules/ingest-geoip/src/test/java/org/elasticsearch/ingest/geoip/DatabaseRegistryTests.java

@@ -122,8 +122,7 @@ public class DatabaseRegistryTests extends ESTestCase {
         resourceWatcherService.close();
         threadPool.shutdownNow();
     }
-
-    @AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/71006")
+    
     public void testCheckDatabases() throws Exception {
         String md5 = mockSearches("GeoIP2-City.mmdb", 5, 14);
         String taskId = GeoIpDownloader.GEOIP_DOWNLOADER;