You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by sa...@apache.org on 2016/06/25 18:53:19 UTC

[28/28] lucene-solr:branch_5_5: Handle adding back compat indexes for versions that are no longer supported

Handle adding back compat indexes for versions that are no longer supported


Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/33ef9eb0
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/33ef9eb0
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/33ef9eb0

Branch: refs/heads/branch_5_5
Commit: 33ef9eb087851ce93cf182b9e93f6fcc383b1c11
Parents: 6868778
Author: Steve Rowe <sa...@apache.org>
Authored: Sat Jun 25 14:26:42 2016 -0400
Committer: Steve Rowe <sa...@apache.org>
Committed: Sat Jun 25 14:51:48 2016 -0400

----------------------------------------------------------------------
 dev-tools/scripts/addBackcompatIndexes.py | 31 ++++++++++++++------------
 dev-tools/scripts/scriptutil.py           |  5 +++++
 2 files changed, 22 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/33ef9eb0/dev-tools/scripts/addBackcompatIndexes.py
----------------------------------------------------------------------
diff --git a/dev-tools/scripts/addBackcompatIndexes.py b/dev-tools/scripts/addBackcompatIndexes.py
index 9e0963d..8a8b5b2 100644
--- a/dev-tools/scripts/addBackcompatIndexes.py
+++ b/dev-tools/scripts/addBackcompatIndexes.py
@@ -30,15 +30,16 @@ import urllib.request
 import re
 import shutil
 
-def create_and_add_index(source, indextype, version, temp_dir):
+def create_and_add_index(source, indextype, index_version, current_version, temp_dir):
   if indextype in ('cfs', 'nocfs'):
     dirname = 'index.%s' % indextype
   else:
     dirname = indextype
+  prefix = 'index' if current_version.is_back_compat_with(index_version) else 'unsupported'
   filename = {
-    'cfs': 'index.%s-cfs.zip',
-    'nocfs': 'index.%s-nocfs.zip'
-  }[indextype] % version
+    'cfs': '%s.%s-cfs.zip',
+    'nocfs': '%s.%s-nocfs.zip'
+  }[indextype] % (prefix, index_version)
   print('  creating %s...' % filename, end='', flush=True)
   module = 'backward-codecs'
   index_dir = os.path.join('lucene', module, 'src/test/org/apache/lucene/index')
@@ -84,11 +85,12 @@ def create_and_add_index(source, indextype, version, temp_dir):
   scriptutil.run('rm -rf %s' % bc_index_dir)
   print('done')
 
-def update_backcompat_tests(types, version):
+def update_backcompat_tests(types, index_version, current_version):
   print('  adding new indexes to backcompat tests...', end='', flush=True)
   module = 'lucene/backward-codecs'
   filename = '%s/src/test/org/apache/lucene/index/TestBackwardsCompatibility.java' % module
-  matcher = re.compile(r'final static String\[\] oldNames = {|};')
+  matcher = re.compile(r'final static String\[\] oldNames = {|};' if current_version.is_back_compat_with(index_version)
+                       else r'final String\[\] unsupportedNames = {|};')
 
   def find_version(x):
     x = x.strip()
@@ -99,17 +101,17 @@ def update_backcompat_tests(types, version):
     start = None
     def __call__(self, buffer, match, line):
       if self.start:
-        # find where we this version should exist
+        # find where this version should exist
         i = len(buffer) - 1 
         v = find_version(buffer[i])
-        while i >= self.start and v.on_or_after(version):
+        while i >= self.start and v.on_or_after(index_version):
           i -= 1
           v = find_version(buffer[i])
         i += 1 # readjust since we skipped past by 1
 
         # unfortunately python doesn't have a range remove from list...
         # here we want to remove any previous references to the version we are adding
-        while i < len(buffer) and version.on_or_after(find_version(buffer[i])):
+        while i < len(buffer) and index_version.on_or_after(find_version(buffer[i])):
           buffer.pop(i)
 
         if i == len(buffer) and not buffer[-1].strip().endswith(","):
@@ -119,7 +121,7 @@ def update_backcompat_tests(types, version):
         last = buffer[-1]
         spaces = ' ' * (len(last) - len(last.lstrip()))
         for (j, t) in enumerate(types):
-          newline = spaces + ('"%s-%s"' % (version, t))
+          newline = spaces + ('"%s-%s"' % (index_version, t))
           if j < len(types) - 1 or i < len(buffer):
             newline += ','
           buffer.insert(i, newline + '\n')
@@ -128,7 +130,7 @@ def update_backcompat_tests(types, version):
         buffer.append(line)
         return True
 
-      if 'oldNames' in line:
+      if 'Names = {' in line:
         self.start = len(buffer) # location of first index name
       buffer.append(line)
       return False
@@ -213,11 +215,12 @@ def main():
 
   print('\nCreating backwards compatibility indexes')
   source = download_release(c.version, c.temp_dir, c.force)
-  create_and_add_index(source, 'cfs', c.version, c.temp_dir)
-  create_and_add_index(source, 'nocfs', c.version, c.temp_dir)
+  current_version = scriptutil.Version.parse(scriptutil.find_current_version())
+  create_and_add_index(source, 'cfs', c.version, current_version, c.temp_dir)
+  create_and_add_index(source, 'nocfs', c.version, current_version, c.temp_dir)
     
   print('\nAdding backwards compatibility tests')
-  update_backcompat_tests(['cfs', 'nocfs'], c.version)
+  update_backcompat_tests(['cfs', 'nocfs'], c.version, current_version)
 
   print('\nTesting changes')
   check_backcompat_tests()

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/33ef9eb0/dev-tools/scripts/scriptutil.py
----------------------------------------------------------------------
diff --git a/dev-tools/scripts/scriptutil.py b/dev-tools/scripts/scriptutil.py
index bf7cec5..9b26413 100644
--- a/dev-tools/scripts/scriptutil.py
+++ b/dev-tools/scripts/scriptutil.py
@@ -66,6 +66,11 @@ class Version(object):
            (self.bugfix > other.bugfix or self.bugfix == other.bugfix and
            self.prerelease >= other.prerelease)))
 
+  def is_back_compat_with(self, other):
+    if not self.on_or_after(other):
+      raise Exception('Back compat check disallowed for newer version: %s < %s' % (self, other))
+    return other.major + 1 >= self.major
+
 def run(cmd):
   try:
     output = subprocess.check_output(cmd, shell=True, stderr=subprocess.STDOUT)