Sha256: 88dc9ab496e4258a574afe2d47e2c7870465a08d98462b44e0c32b824d320b3f

Contents?: true

Size: 1.42 KB

Versions: 3

Compression:

Stored size: 1.42 KB

Contents

module MassiveRecord
  module ORM
    #
    # Module which adds functionality so we rescue errors which might occur on
    # find calls when we are querying tables which does not exist.
    # Small problem with this, which will need to look into.
    #
    module RescueMissingTableOnFind
      def do_find(*args)
        create_table_and_retry_if_table_missing { super }
      end

      def find_in_batches(*args) 
        create_table_and_retry_if_table_missing { super }
      end



      private


      #
      # Yields the block and if any errors occur we will check if table does exist or not.
      # Create it if it's missing and try again.
      #
      # Errors which we'll retry on are:
      #   Apache::Hadoop::Hbase::Thrift::IOError          -> Raised on simple find(id) calls
      #   Apache::Hadoop::Hbase::Thrift::IllegalArgument  -> Raised when a scanner is used
      #
      def create_table_and_retry_if_table_missing # :nodoc:
        begin
          yield
        rescue Apache::Hadoop::Hbase::Thrift::IOError, Apache::Hadoop::Hbase::Thrift::IllegalArgument => error
          if table.exists?
            raise error
          else
            logger.try :info, "*** TABLE MISSING: Table '#{table_name}' seems to be missing. Will create it, then retry call to find()."
            Persistence::Operations::TableOperationHelpers.hbase_create_table!(self)
            yield
          end
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
massive_record-0.2.2 lib/massive_record/orm/finders/rescue_missing_table_on_find.rb
massive_record-0.2.2.rc2 lib/massive_record/orm/finders/rescue_missing_table_on_find.rb
massive_record-0.2.2.rc1 lib/massive_record/orm/finders/rescue_missing_table_on_find.rb