mirror of
https://github.com/apache/lucene.git
synced 2025-02-22 01:56:16 +00:00
Fix bw index generation logic.
This commit is contained in:
parent
47b02dba1e
commit
13d561af1d
@ -45,16 +45,13 @@ def create_and_add_index(source, indextype, index_version, current_version, temp
|
|||||||
'emptyIndex': 'empty'
|
'emptyIndex': 'empty'
|
||||||
}[indextype]
|
}[indextype]
|
||||||
if indextype in ('cfs', 'nocfs'):
|
if indextype in ('cfs', 'nocfs'):
|
||||||
dirname = 'index.%s' % indextype
|
|
||||||
filename = '%s.%s-%s.zip' % (prefix, index_version, indextype)
|
filename = '%s.%s-%s.zip' % (prefix, index_version, indextype)
|
||||||
else:
|
else:
|
||||||
dirname = indextype
|
|
||||||
filename = '%s.%s.zip' % (prefix, index_version)
|
filename = '%s.%s.zip' % (prefix, index_version)
|
||||||
|
|
||||||
print(' creating %s...' % filename, end='', flush=True)
|
print(' creating %s...' % filename, end='', flush=True)
|
||||||
module = 'backward-codecs'
|
module = 'backward-codecs'
|
||||||
index_dir = os.path.join('lucene', module, 'src/test/org/apache/lucene/backward_index')
|
index_dir = os.path.join('lucene', module, 'src/test/org/apache/lucene/backward_index')
|
||||||
test_file = os.path.join(index_dir, filename)
|
|
||||||
if os.path.exists(os.path.join(index_dir, filename)):
|
if os.path.exists(os.path.join(index_dir, filename)):
|
||||||
print('uptodate')
|
print('uptodate')
|
||||||
return
|
return
|
||||||
@ -76,24 +73,20 @@ def create_and_add_index(source, indextype, index_version, current_version, temp
|
|||||||
'-Dtests.codec=default'
|
'-Dtests.codec=default'
|
||||||
])
|
])
|
||||||
base_dir = os.getcwd()
|
base_dir = os.getcwd()
|
||||||
bc_index_dir = os.path.join(temp_dir, dirname)
|
bc_index_file = os.path.join(temp_dir, filename)
|
||||||
bc_index_file = os.path.join(bc_index_dir, filename)
|
|
||||||
|
|
||||||
if os.path.exists(bc_index_file):
|
if os.path.exists(bc_index_file):
|
||||||
print('alreadyexists')
|
print('alreadyexists')
|
||||||
else:
|
else:
|
||||||
if os.path.exists(bc_index_dir):
|
|
||||||
shutil.rmtree(bc_index_dir)
|
|
||||||
os.chdir(source)
|
os.chdir(source)
|
||||||
scriptutil.run('./gradlew %s' % gradle_args)
|
scriptutil.run('./gradlew %s' % gradle_args)
|
||||||
os.chdir(bc_index_dir)
|
if not os.path.exists(bc_index_file):
|
||||||
scriptutil.run('zip %s *' % filename)
|
raise Exception("Expected file can't be found: %s" %bc_index_file)
|
||||||
print('done')
|
print('done')
|
||||||
|
|
||||||
print(' adding %s...' % filename, end='', flush=True)
|
print(' adding %s...' % filename, end='', flush=True)
|
||||||
scriptutil.run('cp %s %s' % (bc_index_file, os.path.join(base_dir, index_dir)))
|
scriptutil.run('cp %s %s' % (bc_index_file, os.path.join(base_dir, index_dir)))
|
||||||
os.chdir(base_dir)
|
os.chdir(base_dir)
|
||||||
scriptutil.run('rm -rf %s' % bc_index_dir)
|
|
||||||
print('done')
|
print('done')
|
||||||
|
|
||||||
def update_backcompat_tests(index_version, current_version):
|
def update_backcompat_tests(index_version, current_version):
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
package org.apache.lucene.backward_index;
|
package org.apache.lucene.backward_index;
|
||||||
|
|
||||||
import com.carrotsearch.randomizedtesting.annotations.Name;
|
import com.carrotsearch.randomizedtesting.annotations.Name;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.LineNumberReader;
|
import java.io.LineNumberReader;
|
||||||
@ -38,11 +39,17 @@ import java.util.function.Predicate;
|
|||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
import java.util.zip.ZipEntry;
|
||||||
|
import java.util.zip.ZipOutputStream;
|
||||||
import org.apache.lucene.codecs.Codec;
|
import org.apache.lucene.codecs.Codec;
|
||||||
import org.apache.lucene.index.DirectoryReader;
|
import org.apache.lucene.index.DirectoryReader;
|
||||||
import org.apache.lucene.index.LeafReaderContext;
|
import org.apache.lucene.index.LeafReaderContext;
|
||||||
import org.apache.lucene.index.SegmentReader;
|
import org.apache.lucene.index.SegmentReader;
|
||||||
import org.apache.lucene.store.Directory;
|
import org.apache.lucene.store.Directory;
|
||||||
|
import org.apache.lucene.store.FSDirectory;
|
||||||
|
import org.apache.lucene.store.IOContext;
|
||||||
|
import org.apache.lucene.store.IndexInput;
|
||||||
|
import org.apache.lucene.store.OutputStreamDataOutput;
|
||||||
import org.apache.lucene.tests.util.LuceneTestCase;
|
import org.apache.lucene.tests.util.LuceneTestCase;
|
||||||
import org.apache.lucene.tests.util.TestUtil;
|
import org.apache.lucene.tests.util.TestUtil;
|
||||||
import org.apache.lucene.util.BytesRef;
|
import org.apache.lucene.util.BytesRef;
|
||||||
@ -253,10 +260,20 @@ public abstract class BackwardsCompatibilityTestBase extends LuceneTestCase {
|
|||||||
protected abstract void createIndex(Directory directory) throws IOException;
|
protected abstract void createIndex(Directory directory) throws IOException;
|
||||||
|
|
||||||
public final void createBWCIndex() throws IOException {
|
public final void createBWCIndex() throws IOException {
|
||||||
Path indexDir = getIndexDir().resolve(indexName(Version.LATEST));
|
Path zipFile = getIndexDir().resolve(indexName(Version.LATEST));
|
||||||
Files.deleteIfExists(indexDir);
|
Files.deleteIfExists(zipFile);
|
||||||
try (Directory dir = newFSDirectory(indexDir)) {
|
Path tmpDir = createTempDir();
|
||||||
|
|
||||||
|
try (Directory dir = FSDirectory.open(tmpDir);
|
||||||
|
ZipOutputStream zipOut = new ZipOutputStream(new FileOutputStream(zipFile.toFile()))) {
|
||||||
createIndex(dir);
|
createIndex(dir);
|
||||||
|
for (String file : dir.listAll()) {
|
||||||
|
try (IndexInput in = dir.openInput(file, IOContext.READONCE)) {
|
||||||
|
zipOut.putNextEntry(new ZipEntry(file));
|
||||||
|
new OutputStreamDataOutput(zipOut).copyBytes(in, in.length());
|
||||||
|
zipOut.closeEntry();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,8 +20,10 @@ import static org.apache.lucene.backward_index.BackwardsCompatibilityTestBase.cr
|
|||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import org.apache.lucene.tests.util.LuceneTestCase;
|
import org.apache.lucene.tests.util.LuceneTestCase;
|
||||||
|
import org.apache.lucene.tests.util.LuceneTestCase.SuppressFileSystems;
|
||||||
import org.apache.lucene.util.Version;
|
import org.apache.lucene.util.Version;
|
||||||
|
|
||||||
|
@SuppressFileSystems("ExtrasFS")
|
||||||
public class TestGenerateBwcIndices extends LuceneTestCase {
|
public class TestGenerateBwcIndices extends LuceneTestCase {
|
||||||
|
|
||||||
// Backcompat index generation, described below, is mostly automated in:
|
// Backcompat index generation, described below, is mostly automated in:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user