int mi_delete_all_rows(MI_INFO *info) { uint i; MYISAM_SHARE *share=info->s; MI_STATE_INFO *state=&share->state; DBUG_ENTER("mi_delete_all_rows"); if (share->options & HA_OPTION_READ_ONLY_DATA) { DBUG_RETURN(my_errno=EACCES); } if (_mi_readinfo(info,F_WRLCK,1)) DBUG_RETURN(my_errno); if (_mi_mark_file_changed(info)) goto err; info->state->records=info->state->del=state->split=0; state->dellink = HA_OFFSET_ERROR; state->sortkey= (ushort) ~0; info->state->key_file_length=share->base.keystart; info->state->data_file_length=0; info->state->empty=info->state->key_empty=0; info->state->checksum=0; for (i=share->base.max_key_block_length/MI_MIN_KEY_BLOCK_LENGTH ; i-- ; ) state->key_del[i]= HA_OFFSET_ERROR; for (i=0 ; i < share->base.keys ; i++) state->key_root[i]= HA_OFFSET_ERROR; myisam_log_command(MI_LOG_DELETE_ALL,info,(uchar*) 0,0,0); /* If we are using delayed keys or if the user has done changes to the tables since it was locked then there may be key blocks in the key cache */ flush_key_blocks(share->key_cache, share->kfile, FLUSH_IGNORE_CHANGED); #ifdef HAVE_MMAP if (share->file_map) mi_munmap_file(info); #endif if (mysql_file_chsize(info->dfile, 0, 0, MYF(MY_WME)) || mysql_file_chsize(share->kfile, share->base.keystart, 0, MYF(MY_WME))) goto err; (void) _mi_writeinfo(info,WRITEINFO_UPDATE_KEYFILE); #ifdef HAVE_MMAP /* Map again */ if (share->file_map) mi_dynmap_file(info, (my_off_t) 0); #endif allow_break(); /* Allow SIGHUP & SIGINT */ DBUG_RETURN(0); err: { int save_errno=my_errno; (void) _mi_writeinfo(info,WRITEINFO_UPDATE_KEYFILE); info->update|=HA_STATE_WRITTEN; /* Buffer changed */ allow_break(); /* Allow SIGHUP & SIGINT */ DBUG_RETURN(my_errno=save_errno); } } /* mi_delete */
int nisam_write(N_INFO *info, const byte *record) { uint i; ulong filepos; uchar *buff; DBUG_ENTER("nisam_write"); DBUG_PRINT("enter",("isam: %d data: %d",info->s->kfile,info->dfile)); if (info->s->base.options & HA_OPTION_READ_ONLY_DATA) { my_errno=EACCES; DBUG_RETURN(-1); } #ifndef NO_LOCKING if (_nisam_readinfo(info,F_WRLCK,1)) DBUG_RETURN(-1); #endif dont_break(); /* Dont allow SIGHUP or SIGINT */ #if !defined(NO_LOCKING) && defined(USE_RECORD_LOCK) if (!info->locked && my_lock(info->dfile,F_WRLCK,0L,F_TO_EOF, MYF(MY_SEEK_NOT_DONE) | info->lock_wait)) goto err; #endif filepos= ((info->s->state.dellink != NI_POS_ERROR) ? info->s->state.dellink : info->s->state.data_file_length); if (info->s->base.reloc == 1L && info->s->base.records == 1L && info->s->state.records == 1L) { /* System file */ my_errno=HA_ERR_RECORD_FILE_FULL; goto err2; } if (info->s->state.key_file_length >= info->s->base.max_key_file_length - info->s->blocksize* INDEX_BLOCK_MARGIN *info->s->state.keys) { my_errno=HA_ERR_INDEX_FILE_FULL; goto err2; } /* Write all keys to indextree */ buff=info->lastkey+info->s->base.max_key_length; for (i=0 ; i < info->s->state.keys ; i++) { VOID(_nisam_make_key(info,i,buff,record,filepos)); if (_nisam_ck_write(info,i,buff)) goto err; } if ((*info->s->write_record)(info,record)) goto err; info->update= (HA_STATE_CHANGED | HA_STATE_ROW_CHANGED |HA_STATE_AKTIV | HA_STATE_WRITTEN); info->s->state.records++; info->lastpos=filepos; nisam_log_record(LOG_WRITE,info,record,filepos,0); VOID(_nisam_writeinfo(info,1)); allow_break(); /* Allow SIGHUP & SIGINT */ DBUG_RETURN(0); err: if (my_errno == HA_ERR_FOUND_DUPP_KEY || my_errno == HA_ERR_RECORD_FILE_FULL) { info->errkey= (int) i; while ( i-- > 0) { VOID(_nisam_make_key(info,i,buff,record,filepos)); if (_nisam_ck_delete(info,i,buff)) break; } } info->update=(HA_STATE_CHANGED | HA_STATE_ROW_CHANGED | HA_STATE_WRITTEN); err2: nisam_log_record(LOG_WRITE,info,record,filepos,my_errno); VOID(_nisam_writeinfo(info,1)); allow_break(); /* Allow SIGHUP & SIGINT */ DBUG_RETURN(-1); } /* nisam_write */
int nisam_update(register N_INFO *info, const byte *oldrec, const byte *newrec) { int flag,key_changed,save_errno; reg3 ulong pos; uint i,length; uchar old_key[N_MAX_KEY_BUFF],*new_key; DBUG_ENTER("nisam_update"); LINT_INIT(save_errno); if (!(info->update & HA_STATE_AKTIV)) { my_errno=HA_ERR_KEY_NOT_FOUND; DBUG_RETURN(-1); } if (info->s->base.options & HA_OPTION_READ_ONLY_DATA) { my_errno=EACCES; DBUG_RETURN(-1); } pos=info->lastpos; #ifndef NO_LOCKING if (_nisam_readinfo(info,F_WRLCK,1)) DBUG_RETURN(-1); #endif if ((*info->s->compare_record)(info,oldrec)) { save_errno=my_errno; goto err_end; /* Record has changed */ } if (info->s->state.key_file_length >= info->s->base.max_key_file_length - info->s->blocksize* INDEX_BLOCK_MARGIN *info->s->state.keys) { save_errno=HA_ERR_INDEX_FILE_FULL; goto err_end; } /* Flyttar de element i isamfilen som m}ste flyttas */ new_key=info->lastkey+info->s->base.max_key_length; key_changed=HA_STATE_KEY_CHANGED; /* We changed current database */ /* Remove key that didn't change */ for (i=0 ; i < info->s->state.keys ; i++) { length=_nisam_make_key(info,i,new_key,newrec,pos); if (length != _nisam_make_key(info,i,old_key,oldrec,pos) || memcmp((byte*) old_key,(byte*) new_key,length)) { if ((int) i == info->lastinx) key_changed|=HA_STATE_WRITTEN; /* Mark that keyfile changed */ if (_nisam_ck_delete(info,i,old_key)) goto err; if (_nisam_ck_write(info,i,new_key)) goto err; } } if ((*info->s->update_record)(info,pos,newrec)) goto err; info->update= (HA_STATE_CHANGED | HA_STATE_ROW_CHANGED | HA_STATE_AKTIV | key_changed); nisam_log_record(LOG_UPDATE,info,newrec,info->lastpos,0); VOID(_nisam_writeinfo(info,test(key_changed))); allow_break(); /* Allow SIGHUP & SIGINT */ DBUG_RETURN(0); err: DBUG_PRINT("error",("key: %d errno: %d",i,my_errno)); save_errno=my_errno; if (my_errno == HA_ERR_FOUND_DUPP_KEY || my_errno == HA_ERR_RECORD_FILE_FULL) { info->errkey= (int) i; flag=0; do { length=_nisam_make_key(info,i,new_key,newrec,pos); if (length != _nisam_make_key(info,i,old_key,oldrec,pos) || memcmp((byte*) old_key,(byte*) new_key,length)) { if ((flag++ && _nisam_ck_delete(info,i,new_key)) || _nisam_ck_write(info,i,old_key)) break; } } while (i-- != 0); } info->update= (HA_STATE_CHANGED | HA_STATE_ROW_CHANGED | HA_STATE_AKTIV | key_changed); err_end: nisam_log_record(LOG_UPDATE,info,newrec,info->lastpos,save_errno); VOID(_nisam_writeinfo(info,1)); allow_break(); /* Allow SIGHUP & SIGINT */ my_errno=(save_errno == HA_ERR_KEY_NOT_FOUND) ? HA_ERR_CRASHED : save_errno; DBUG_RETURN(-1); } /* nisam_update */
int mi_write(MI_INFO * info, byte * record) { uint i; int save_errno; my_off_t filepos; uchar *buff; MYISAM_SHARE *share = info->s; DBUG_ENTER("mi_write"); DBUG_PRINT("enter", ("isam: %d data: %d", info->s->kfile, info->dfile)); if (share->options & HA_OPTION_READ_ONLY_DATA) { DBUG_RETURN(my_errno = EACCES); } if (_mi_readinfo(info, F_WRLCK, 1)) DBUG_RETURN(my_errno); dont_break(); /* Dont allow SIGHUP or SIGINT */ #if !defined(NO_LOCKING) && defined(USE_RECORD_LOCK) if (!info->locked && my_lock(info->dfile, F_WRLCK, 0L, F_TO_EOF, MYF(MY_SEEK_NOT_DONE) | info->lock_wait)) goto err; #endif filepos = ((share->state.dellink != HA_OFFSET_ERROR) ? share->state.dellink : info->state->data_file_length); if (share->base.reloc == (ha_rows) 1 && share->base.records == (ha_rows) 1 && info->state->records == (ha_rows) 1) { /* System file */ my_errno = HA_ERR_RECORD_FILE_FULL; goto err2; } if (info->state->key_file_length >= share->base.margin_key_file_length) { my_errno = HA_ERR_INDEX_FILE_FULL; goto err2; } if (_mi_mark_file_changed(info)) goto err2; /* Calculate and check all unique constraints */ for (i = 0; i < share->state.header.uniques; i++) { if (mi_check_unique(info, share->uniqueinfo + i, record, mi_unique_hash(share->uniqueinfo + i, record), HA_OFFSET_ERROR)) goto err2; } /* Write all keys to indextree */ buff = info->lastkey2; for (i = 0; i < share->base.keys; i++) { if (((ulonglong) 1 << i) & share->state.key_map) { if (share->concurrent_insert) { rw_wrlock(&share->key_root_lock[i]); share->keyinfo[i].version++; } if (share->keyinfo[i].flag & HA_FULLTEXT) { /* SerG *//* SerG */ if (_mi_ft_add(info, i, (char *)buff, record, filepos)) { /* SerG *//* SerG */ if (share->concurrent_insert) rw_unlock(&share->key_root_lock[i]); DBUG_PRINT("error", ("Got error: %d on write", my_errno)); /* SerG */ goto err; /* SerG */ } /* SerG */ } /* SerG */ else { /* SerG */ uint key_length = _mi_make_key(info, i, buff, record, filepos); if (_mi_ck_write(info, i, buff, key_length)) { if (share->concurrent_insert) rw_unlock(&share->key_root_lock[i]); DBUG_PRINT("error", ("Got error: %d on write", my_errno)); goto err; } } if (share->concurrent_insert) rw_unlock(&share->key_root_lock[i]); } } if (share->calc_checksum) info->checksum = (*share->calc_checksum) (info, record); if (!(info->opt_flag & OPT_NO_ROWS)) { if ((*share->write_record) (info, record)) goto err; share->state.checksum += info->checksum; } if (share->base.auto_key) update_auto_increment(info, record); info->update = (HA_STATE_CHANGED | HA_STATE_AKTIV | HA_STATE_WRITTEN | HA_STATE_ROW_CHANGED); info->state->records++; info->lastpos = filepos; myisam_log_record(MI_LOG_WRITE, info, record, filepos, 0); VOID(_mi_writeinfo(info, WRITEINFO_UPDATE_KEYFILE)); allow_break(); /* Allow SIGHUP & SIGINT */ DBUG_RETURN(0); err: save_errno = my_errno; if (my_errno == HA_ERR_FOUND_DUPP_KEY || my_errno == HA_ERR_RECORD_FILE_FULL) { info->errkey = (int)i; while (i-- > 0) { if (((ulonglong) 1 << i) & share->state.key_map) { if (share->concurrent_insert) rw_wrlock(&share->key_root_lock[i]); /* * The following code block is for text * searching by SerG */ if (share->keyinfo[i].flag & HA_FULLTEXT) { if (_mi_ft_del(info, i, (char *)buff, record, filepos)) { if (share->concurrent_insert) rw_unlock(&share->key_root_lock[i]); break; } } else { uint key_length = _mi_make_key(info, i, buff, record, filepos); if (_mi_ck_delete(info, i, buff, key_length)) { if (share->concurrent_insert) rw_unlock(&share->key_root_lock[i]); break; } } if (share->concurrent_insert) rw_unlock(&share->key_root_lock[i]); } } } else mi_mark_crashed(info); info->update = (HA_STATE_CHANGED | HA_STATE_WRITTEN | HA_STATE_ROW_CHANGED); my_errno = save_errno; err2: save_errno = my_errno; myisam_log_record(MI_LOG_WRITE, info, record, filepos, my_errno); VOID(_mi_writeinfo(info, WRITEINFO_UPDATE_KEYFILE)); allow_break(); /* Allow SIGHUP & SIGINT */ DBUG_RETURN(my_errno = save_errno); } /* mi_write */