// Split a Chunk and insert new Chunk after it
void Aggregate::split(std::vector<Chunk*>::size_type split_index){

    Chunk* cell = m_chunk[split_index];
    cell->txn()->pause();

    // Calculate the split point ie midpoint
    // Note: Range is exclusive of previous session
    uintmax_t downloaded = cell->txn()->bytesDone();
    uintmax_t lower = cell->txn()->range().lb();
    uintmax_t upper = cell->txn()->range().ub();
    uintmax_t midpoint = (upper+(lower+downloaded))/2;

    if( midpoint > upper || midpoint < lower)
        Throw(ex::Invalid,"Midpoint");

    // Update the upper byte of the byte range.
    // no bytes beyond a certain point.
    cell->txn()->range().ub(midpoint);
    cell->txn()->play();

    Range newrange(upper,midpoint);
    File* newfile = new File(chunkName(midpoint));
    BasicTransaction* newtxn = cell->txn()->clone(newrange);
    Chunk* newcell = new Chunk(newtxn,newfile);

    // Insert newly created Chunk in the vector after
    m_chunk.insert(m_chunk.begin()+split_index+1, newcell);

    newcell->txn()->start();
}
Пример #2
0
int mainloop()
{
  unsigned cmd;
  nodep myLine;
  extern int phys_pcode;
  extern int row, scol, ecol;
  int curserr;

  for (;;) {
    here(1);
    checkfar(1);
    printt5("mainloop, cursor %x, ocursor %x, srch_row %d, srch_real %d, look.=%x\n",
	    cursor, ocursor, srch_row, srch_real, lookaheadchar);
    hist_mark();
    printt0("back from hist_mark()\n");
    if (lookaheadchar == AL_NOP || lookaheadchar == ' ')
      lookaheadchar = 0;
    /*
     * Redisplay unconditionally, not just when there's no
     * typeahead, because often there is typeahead of the
     * terminating character, like comma or right paren.
     * Ideally the redisplay should be done only if dirty
     * from the keyboard driver when we are ready for real
     * input.
     */
    newrange(FALSE);
    display(FALSE);

    /*
     * ocursor is set by arrow keys to indicate that that's
     * where the arrow keys left the cursor.  Only if it
     * was set (possibly in them middle of a token) and
     * hasn't moved since do we want to leave it alone.
     */
    here(2);
    checkfar(2);
    if (cursor != ocursor) {
      /* don't do if moves are in type-ahead */
      find_phys_cursor( curr_window, cursor,anywflag);
      anywflag = FALSE;
      phys_pcode = kcget( -1, cursor );
      flusht();
    }
    here(3);
    ocursor = NIL;
    CheckAt = NIL;
    CodeChanged = FALSE;
    if( autsave &&  ascount++ > autsave ) {
      ascount = 0;
      if( work_fname( curr_workspace ) )  {
	save(0);
	statusLine();
      }
      else
	warning( ER(220,"autosave`Automatic Save is engaged but there is no file name.") );

    }
    here(4);
    cmd = topcmd( srch_row, srch_real, srch_real+srch_width, cursnode );
    printt2("mainloop: topcmd returns %s (%d)\n", tokname(cmd), cmd);

    mark_line( cursor, SMALL_CHANGE );

    do_command(cmd);

    here(5);
    checkfar(3);
    /* never leave the cursor on a list or below hide */
    cursor = hidebound(realcp( cursor ));

    mark_line( cursor, SMALL_CHANGE );
    curserr = node_flag(cursor) & NF_ERROR;
    if( curserr && !WhereDeclsChanged )
    {
       NodeNum cltype = ntype( t_up_to_line(cursor));
       if( ntype_info(cltype) & F_DECLARE||highType( cltype ) ) 
       {
	  WhereDeclsChanged = my_block(cursor);
	  printt1("mainloop: WhereDeclsChanged=%x\n",
		  WhereDeclsChanged);
       }
    }

    /*
     * Whenever a graft, etc takes place we check to see
     * if changes are being made to a declaration.  If they
     * are then we set WhereDeclsChanged.  If it has been
     * set when we get back here we recompile its declaration
     * block.
     */
    if (CheckSpeed && WhereDeclsChanged && 
	(CheckSpeed >= 4 || CodeChanged || 
	 WhereDeclsChanged != OldDeclsChanged) )
    {
       if( CheckSpeed < 4 && WhereDeclsChanged != OldDeclsChanged )
       {
	  nodep decswap;
	  decswap = OldDeclsChanged;
	  OldDeclsChanged = WhereDeclsChanged;
	  WhereDeclsChanged = decswap;
	  printt1("mainloop: WhereDeclsChanged=%x (2)\n",
		  WhereDeclsChanged);
       }
       
       if( WhereDeclsChanged )
       {
	  clr_node_flag(WhereDeclsChanged, NF_TCHECKED);
	  here(4);
	  checkfar(4);
	  c_comp_decls(my_scope(WhereDeclsChanged),
		       WhereDeclsChanged,
		       CheckSpeed < 6 ? TC_NOSTUBS :
		       (TC_DESCEND | TC_FULL) );
	  here(5);
	  checkfar(5);
	  WhereDeclsChanged = NIL;
       }
    }

    /*
     * Typecheck the current line.  This was added late in the
     * game, and isn't really the best way of doing things.
     * Every time we return from a command, we typecheck
     * the current line (or if CheckAt has already been set
     * by a skip down routine, we typecheck there).  We
     * don't typecheck declarations.
     */
    printt2("CheckAt=%x, cursor=%x\n", CheckAt, cursor);
    if (!CheckAt && (curserr||is_undid(cursor))) CheckAt = cursor;
    if( CheckAt && CheckSpeed )
    {
       myLine = t_up_to_line(CheckAt);
       if (!( highType(ntype(myLine)) ||
	      (ntype_info(ntype(myLine)) & F_DECLARE)) )
       {
	  printt2("mainloop: c_typecheck(%x, 0, %x)\n",
		  (int)myLine,  TC_NOSTUBS|TC_ONERROR);
	  c_typecheck(myLine, 0, TC_NOSTUBS|TC_ONERROR );
	  here(6);
	  checkfar(6);
       }
    }

    /* if code was changed, clear chance at resuming */
    if( CodeChanged )
       clear_resume();
#ifdef CHECKSUM
    cscheck();
#endif
  }
}