lucy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mar...@apache.org
Subject svn commit: r902833 - in /lucene/lucy/trunk/core/Lucy/Store: CompoundFileReader.c CompoundFileWriter.c
Date Mon, 25 Jan 2010 14:50:27 GMT
Author: marvin
Date: Mon Jan 25 14:50:27 2010
New Revision: 902833

URL: http://svn.apache.org/viewvc?rev=902833&view=rev
Log:
Temporarily downgrade the compound file format. 

Modified:
    lucene/lucy/trunk/core/Lucy/Store/CompoundFileReader.c
    lucene/lucy/trunk/core/Lucy/Store/CompoundFileWriter.c

Modified: lucene/lucy/trunk/core/Lucy/Store/CompoundFileReader.c
URL: http://svn.apache.org/viewvc/lucene/lucy/trunk/core/Lucy/Store/CompoundFileReader.c?rev=902833&r1=902832&r2=902833&view=diff
==============================================================================
--- lucene/lucy/trunk/core/Lucy/Store/CompoundFileReader.c (original)
+++ lucene/lucy/trunk/core/Lucy/Store/CompoundFileReader.c Mon Jan 25 14:50:27 2010
@@ -6,6 +6,7 @@
 #include "Lucy/Store/CompoundFileWriter.h"
 #include "Lucy/Store/FileHandle.h"
 #include "Lucy/Store/InStream.h"
+#include "Lucy/Util/IndexFileNames.h"
 #include "Lucy/Util/Json.h"
 #include "Lucy/Util/StringHelper.h"
 
@@ -75,19 +76,21 @@
     if (self->format == 1) {
         VArray *files = Hash_Keys(self->records);
         ZombieCharBuf filename = ZCB_BLANK;
-        CharBuf *folder_path = Folder_Get_Path(folder);
-        size_t folder_path_len = CB_Length(folder_path);
-        u32_t i, max;
+        ZombieCharBuf folder_name = ZCB_BLANK;
+        IxFileNames_local_part(Folder_Get_Path(folder), &folder_name);
+        size_t folder_name_len = ZCB_Length(&folder_name);
 
-        for (i = 0, max = VA_Get_Size(files); i < max; i++) {
+        for (uint32_t i = 0, max = VA_Get_Size(files); i < max; i++) {
             CharBuf *orig = (CharBuf*)VA_Fetch(files, i);
-            if (CB_Starts_With(orig, folder_path)) {
+            if (CB_Starts_With(orig, (CharBuf*)&folder_name)) {
                 Obj *record = Hash_Delete(self->records, (Obj*)orig);
                 ZCB_Assign(&filename, orig);
-                ZCB_Nip(&filename, folder_path_len + sizeof(DIR_SEP) - 1);
+                ZCB_Nip(&filename, folder_name_len + sizeof(DIR_SEP) - 1);
                 Hash_Store(self->records, (Obj*)&filename, (Obj*)record);
             }
         }
+
+        DECREF(files);
     }
 
     return self;

Modified: lucene/lucy/trunk/core/Lucy/Store/CompoundFileWriter.c
URL: http://svn.apache.org/viewvc/lucene/lucy/trunk/core/Lucy/Store/CompoundFileWriter.c?rev=902833&r1=902832&r2=902833&view=diff
==============================================================================
--- lucene/lucy/trunk/core/Lucy/Store/CompoundFileWriter.c (original)
+++ lucene/lucy/trunk/core/Lucy/Store/CompoundFileWriter.c Mon Jan 25 14:50:27 2010
@@ -5,9 +5,10 @@
 #include "Lucy/Store/Folder.h"
 #include "Lucy/Store/InStream.h"
 #include "Lucy/Store/OutStream.h"
+#include "Lucy/Util/IndexFileNames.h"
 #include "Lucy/Util/Json.h"
 
-i32_t CFWriter_current_file_format = 2;
+i32_t CFWriter_current_file_format = 1;
 
 static ZombieCharBuf cfmeta_file = ZCB_LITERAL("cfmeta.json");
 static ZombieCharBuf cfmeta_temp = ZCB_LITERAL("cfmeta.json.temp");
@@ -80,6 +81,7 @@
     Hash      *metadata     = Hash_new(0);
     Hash      *sub_files    = Hash_new(0);
     VArray    *files        = Folder_List(folder, NULL);
+    VArray    *merged       = VA_new(VA_Get_Size(files));
     OutStream *outstream    = Folder_Open_Out(folder, (CharBuf*)&cf_file);
     u32_t      i, max;
     bool_t     rename_success;
@@ -91,6 +93,17 @@
     Hash_Store_Str(metadata, "format", 6, 
         (Obj*)CB_newf("%i32", CFWriter_current_file_format) );
 
+    /* Temporary hack!  Prepend the segment name for compatibility with
+     * earlier releases. */
+    CharBuf *infilepath = CB_new(30);
+    bool_t base_len = 0;
+    ZombieCharBuf seg_name = ZCB_BLANK;
+    IxFileNames_local_part(Folder_Get_Path(folder), &seg_name);
+    if (ZCB_Starts_With_Str(&seg_name, "seg_", 4)) {
+        CB_setf(infilepath, "%o/", &seg_name);
+        base_len = CB_Get_Size(infilepath);
+    }
+
     VA_Sort(files, NULL, NULL);
     for (i = 0, max = VA_Get_Size(files); i < max; i++) {
         CharBuf *infilename = (CharBuf*)VA_Fetch(files, i);
@@ -112,7 +125,10 @@
                 (Obj*)CB_newf("%i64", offset) );
             Hash_Store_Str(file_data, "length", 6, 
                 (Obj*)CB_newf("%i64", len) );
-            Hash_Store(sub_files, (Obj*)infilename, (Obj*)file_data);
+            CB_Set_Size(infilepath, base_len);
+            CB_Cat(infilepath, infilename);
+            Hash_Store(sub_files, (Obj*)infilepath, (Obj*)file_data);
+            VA_Push(merged, INCREF(infilename));
 
             /* Add filler NULL bytes so that every sub-file begins on a file
              * position multiple of 8. */
@@ -125,6 +141,7 @@
             DECREF(instream);
         }
     }
+    DECREF(infilepath);
 
     /* Write metadata to cfmeta file. */
     Json_spew_json((Obj*)metadata, (Folder*)self->folder,
@@ -139,6 +156,7 @@
     DECREF(files);
     DECREF(metadata);
     {
+        /*
         CharBuf *merged_file;
         Obj     *ignore;
         Hash_Iter_Init(sub_files);
@@ -149,8 +167,18 @@
                 Err_throw_mess(ERR, mess);
             }
         }
+        */
     }
     DECREF(sub_files);
+    for (uint32_t i = 0, max = VA_Get_Size(merged); i < max; i++) {
+        CharBuf *merged_file = (CharBuf*)VA_Fetch(merged, i);
+        if (!Folder_Delete(folder, merged_file)) {
+            CharBuf *mess = MAKE_MESS("Can't delete '%o'", merged_file);
+            DECREF(merged);
+            Err_throw_mess(ERR, mess);
+        }
+    }
+    DECREF(merged);
 }
 
 /* Copyright 2009 The Apache Software Foundation



Mime
View raw message