lucy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mar...@apache.org
Subject [lucy-commits] svn commit: r1327334 - in /lucy/trunk: c/src/Lucy/Index/PolyReader.c core/Lucy/Index/PolyReader.c core/Lucy/Index/PolyReader.cfh example-lang/src/Lucy/Index/PolyReader.c perl/lib/Lucy.pm perl/xs/Lucy/Index/PolyReader.c ruby/src/Lucy/Index/PolyReader.c
Date Wed, 18 Apr 2012 00:00:11 GMT
Author: marvin
Date: Wed Apr 18 00:00:11 2012
New Revision: 1327334

URL: http://svn.apache.org/viewvc?rev=1327334&view=rev
Log:
Trap errors locally when opening SegReaders.

Use Err#trap to trap errors when opening individual SegReaders,
eliminating a host callback.

Removed:
    lucy/trunk/c/src/Lucy/Index/PolyReader.c
    lucy/trunk/example-lang/src/Lucy/Index/PolyReader.c
    lucy/trunk/perl/xs/Lucy/Index/PolyReader.c
    lucy/trunk/ruby/src/Lucy/Index/PolyReader.c
Modified:
    lucy/trunk/core/Lucy/Index/PolyReader.c
    lucy/trunk/core/Lucy/Index/PolyReader.cfh
    lucy/trunk/perl/lib/Lucy.pm

Modified: lucy/trunk/core/Lucy/Index/PolyReader.c
URL: http://svn.apache.org/viewvc/lucy/trunk/core/Lucy/Index/PolyReader.c?rev=1327334&r1=1327333&r2=1327334&view=diff
==============================================================================
--- lucy/trunk/core/Lucy/Index/PolyReader.c (original)
+++ lucy/trunk/core/Lucy/Index/PolyReader.c Wed Apr 18 00:00:11 2012
@@ -52,6 +52,18 @@ struct try_read_snapshot_context {
 static void
 S_try_read_snapshot(void *context);
 
+// Try to open an individual SegReader.
+struct try_open_segreader_context {
+    Schema    *schema;
+    Folder    *folder;
+    Snapshot  *snapshot;
+    VArray    *segments;
+    int32_t    seg_tick;
+    SegReader *result;
+};
+static void
+S_try_open_segreader(void *context);
+
 static Folder*
 S_derive_folder(Obj *index);
 
@@ -185,6 +197,14 @@ S_try_read_snapshot(void *context) {
     Snapshot_Read_File(args->snapshot, args->folder, args->path);
 }
 
+static void
+S_try_open_segreader(void *context) {
+    struct try_open_segreader_context *args
+        = (struct try_open_segreader_context*)context;
+    args->result = SegReader_new(args->schema, args->folder, args->snapshot,
+                                 args->segments, args->seg_tick);
+}
+
 Obj*
 S_try_open_elements(PolyReader *self) {
     VArray   *files             = Snapshot_List(self->snapshot);
@@ -216,7 +236,7 @@ S_try_open_elements(PolyReader *self) {
     if (!schema_file) {
         CharBuf *mess = MAKE_MESS("Can't find a schema file.");
         DECREF(files);
-        return (Obj*)mess;
+        return (Obj*)Err_new(mess);
     }
     else {
         Hash *dump = (Hash*)Json_slurp_json(folder, schema_file);
@@ -232,7 +252,7 @@ S_try_open_elements(PolyReader *self) {
             CharBuf *mess = MAKE_MESS("Failed to parse %o", schema_file);
             DECREF(schema_file);
             DECREF(files);
-            return (Obj*)mess;
+            return (Obj*)Err_new(mess);
         }
     }
 
@@ -256,7 +276,7 @@ S_try_open_elements(PolyReader *self) {
                 DECREF(segment);
                 DECREF(segments);
                 DECREF(files);
-                return (Obj*)mess;
+                return (Obj*)Err_new(mess);
             }
         }
     }
@@ -264,11 +284,34 @@ S_try_open_elements(PolyReader *self) {
     // Sort the segments by age.
     VA_Sort(segments, NULL, NULL);
 
-    Obj *result = PolyReader_Try_Open_SegReaders(self, segments);
+    // Open individual SegReaders.
+    struct try_open_segreader_context context;
+    context.schema   = PolyReader_Get_Schema(self);
+    context.folder   = folder;
+    context.snapshot = PolyReader_Get_Snapshot(self);
+    context.segments = segments;
+    context.result   = NULL;
+    VArray *seg_readers = VA_new(num_segs);
+    Err *error = NULL;
+    for (uint32_t seg_tick = 0; seg_tick < num_segs; seg_tick++) {
+        context.seg_tick = seg_tick;
+        error = Err_trap(S_try_open_segreader, &context);
+        if (error) {
+            break;
+        }
+        VA_Push(seg_readers, (Obj*)context.result);
+        context.result = NULL;
+    }
+
     DECREF(segments);
     DECREF(files);
-    return result;
-
+    if (error) {
+        DECREF(seg_readers);
+        return (Obj*)error;
+    }
+    else {
+        return (Obj*)seg_readers;
+    }
 }
 
 // For test suite.
@@ -367,7 +410,7 @@ PolyReader_do_open(PolyReader *self, Obj
          * If we can, then the exception was due to the race condition.  If
          * not, we have a real exception, so throw an error. */
         Obj *result = S_try_open_elements(self);
-        if (Obj_Is_A(result, CHARBUF)) { // Error occurred.
+        if (Obj_Is_A(result, ERR)) { // Error occurred.
             S_release_read_lock(self);
             DECREF(target_snap_file);
             if (last_gen < gen) { // Index updated, so try again.
@@ -376,7 +419,7 @@ PolyReader_do_open(PolyReader *self, Obj
             }
             else { // Real error.
                 if (manager) { S_release_deletion_lock(self); }
-                Err_throw_mess(ERR, (CharBuf*)result);
+                RETHROW(result);
             }
         }
         else { // Succeeded.

Modified: lucy/trunk/core/Lucy/Index/PolyReader.cfh
URL: http://svn.apache.org/viewvc/lucy/trunk/core/Lucy/Index/PolyReader.cfh?rev=1327334&r1=1327333&r2=1327334&view=diff
==============================================================================
--- lucy/trunk/core/Lucy/Index/PolyReader.cfh (original)
+++ lucy/trunk/core/Lucy/Index/PolyReader.cfh Wed Apr 18 00:00:11 2012
@@ -56,13 +56,6 @@ class Lucy::Index::PolyReader inherits L
          Snapshot *snapshot = NULL, IndexManager *manager = NULL,
          VArray *sub_readers = NULL);
 
-    /** Attempt to open a SegReader for each Segment that the Snapshot knows
-     * about.  If an exception occurs, catch it and return its error message.
-     * If the opening succeeds, return a VArray full of SegReaders.
-     */
-    incremented Obj*
-    Try_Open_SegReaders(PolyReader *self, VArray *segments);
-
     inert CharBuf* race_condition_debug1;
     inert int32_t  debug1_num_passes;
 

Modified: lucy/trunk/perl/lib/Lucy.pm
URL: http://svn.apache.org/viewvc/lucy/trunk/perl/lib/Lucy.pm?rev=1327334&r1=1327333&r2=1327334&view=diff
==============================================================================
--- lucy/trunk/perl/lib/Lucy.pm (original)
+++ lucy/trunk/perl/lib/Lucy.pm Wed Apr 18 00:00:11 2012
@@ -218,41 +218,6 @@ sub error {$Lucy::Object::Err::error}
 }
 
 {
-    package Lucy::Index::PolyReader;
-    our $VERSION = '0.003000';
-    $VERSION = eval $VERSION;
-    use Lucy qw( to_clownfish );
-
-    sub _try_open_segreaders {
-        my ( $self, $segments ) = @_;
-        my $schema   = $self->get_schema;
-        my $folder   = $self->get_folder;
-        my $snapshot = $self->get_snapshot;
-        my $seg_readers
-            = Lucy::Object::VArray->new( capacity => scalar @$segments );
-        my $segs = to_clownfish($segments);    # FIXME: Don't convert twice.
-        eval {
-            # Create a SegReader for each segment in the index.
-            my $num_segs = scalar @$segments;
-            for ( my $seg_tick = 0; $seg_tick < $num_segs; $seg_tick++ ) {
-                my $seg_reader = Lucy::Index::SegReader->new(
-                    schema   => $schema,
-                    folder   => $folder,
-                    segments => $segs,
-                    seg_tick => $seg_tick,
-                    snapshot => $snapshot,
-                );
-                $seg_readers->push($seg_reader);
-            }
-        };
-        if ($@) {
-            return Lucy::Object::CharBuf->new($@);
-        }
-        return $seg_readers;
-    }
-}
-
-{
     package Lucy::Index::Segment;
     our $VERSION = '0.003000';
     $VERSION = eval $VERSION;



Mime
View raw message