Ignore:
Timestamp:
2018-11-07T20:44:34+13:00 (5 years ago)
Author:
ak19
Message:

Now that previous commit(s) put sig handlers in place in gs_sql, have been able to add in Undo on build/import Cancel for the GS SQL Plugs. This utilizes AutoCommit vs Transaction (rollback/commit) behaviour. On cancel, a sig handler is triggered (SIGINT) and, if AutoCommit is off, does a rollback before die() which calls object destructor and disconnects from db. On regular program execution running to normal termination, the last finish() call on gs_sql that will trigger the disconnect, will now first do a commit(), if AutoCommit is off, before disconnecting. For now, the default for both GreenstoneSQLPlugs is to support Undo (i.e. transactions), which turns AutoCommit off. Not sure whether this will be robust: what if transactions take place in memory, we could be dealing with millions of docs of large full-txt. Another issue is that the SQL DB may be out of sync with archives and index folder on Cancel: archives and index just terminate and are in an intermediate state depending on when cancel was pressed. Whereas the GS SQL DB is in a rolled back state as if the import or build never took place. A third issue is that during buildcol (perhaps specifically during buildcol's doc processing phase), pressing Cancel still continues buildcol: the current perl process is cancelled but the next one continues, rather than terminating buildcol in entirety. What happens with the GS SQL DB is that any 'transaction' until then is rolled back, perhaps a transaction regarding one doc if the Cancel affects on a doc basis, and the next process (next doc processing?) continues and allows for further transactions that are all committed at the end on natural termination of buildcol. Need to whether Undo behavious is really what we want. But it's available now and we can simply change the default to not support Undo if we want the old behaviour again.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone2/perllib/plugins/GreenstoneSQLPlugin.pm

    r32580 r32582  
    137137        'desc' => "{GreenstoneSQLPlug.process_mode.all}" } ];
    138138
     139my $rollback_on_cancel_list =
     140    [ { 'name' => "true",
     141        'desc' => "{GreenstoneSQLPlug.rollback_on_cancel}" },     
     142      { 'name' => "false",
     143        'desc' => "{GreenstoneSQLPlug.rollbacl_on_cancel}" } ];
     144
    139145my $arguments =
    140146    [ { 'name' => "process_exp",
     
    149155    'deft' => "all",
    150156    'reqd' => "no"},
     157      { 'name' => "rollback_on_cancel",
     158    'desc' => "{GreenstoneSQLPlug.rollback_on_cancel}",
     159    'type' => "enum",
     160    'list' => $rollback_on_cancel_list,
     161    'deft' => "true", # TODO Q: what's the better default? If "true", any memory concerns?
     162    'reqd' => "no",
     163    'hiddengli' => "no"},
    151164      { 'name' => "db_driver",
    152165    'desc' => "{GreenstoneSQLPlug.db_driver}",
     
    204217}
    205218
     219###### Called during import.pl
     220
    206221# This is called once if removeold is set with import.pl. Most plugins will do
    207222# nothing but if a plugin does any stuff outside of creating doc obj, then
     
    230245    $gs_sql->ensure_fulltxt_table_exists();
    231246    }
    232 }
    233 
    234 # This is called per document for docs that have been deleted from the
     247
     248    # UNNECESSARY
     249    # The removeold related DB transaction (deleting collection tables) is complete
     250    # Don't let GS SQL PlugIN interfere with GS SQL PlugOUT's database transactions
     251    # during import.pl hereafter. Finish up.
     252    #$gs_sql->do_commit_if_on();
     253}
     254
     255# This is called during import.pl per document for docs that have been deleted from the
    235256# collection. Most plugins will do nothing
    236257# but if a plugin does any stuff outside of creating doc obj, then it may need
     
    273294}
    274295
     296#### Called during buildcol
    275297
    276298sub xml_start_tag {
     
    395417}
    396418
     419#### Called during buildcol and import
    397420
    398421# GS SQL Plugin::init() (and deinit()) is called by import.pl and also by buildcol.pl
     
    429452    'verbosity' => $self->{'verbosity'} || 0
    430453               });
     454   
     455    # if autocommit is set, there's no rollback support
     456    my $autocommit = ($self->{'rollback_on_cancel'} eq "false") ? 1 : 0;
    431457
    432458    # try connecting to the mysql db, die if that fails
     
    435461    'db_client_user' => $self->{'db_client_user'},
    436462    'db_client_pwd' => $self->{'db_client_pwd'},
    437     'db_host' => $self->{'db_host'}
     463    'db_host' => $self->{'db_host'},
     464    'autocommit' => $autocommit
    438465                   })
    439466    )
Note: See TracChangeset for help on using the changeset viewer.