~ubuntu-branches/ubuntu/utopic/mariadb-5.5/utopic-security

« back to all changes in this revision

Viewing changes to storage/tokudb/ft-index/src/ydb_write.cc

  • Committer: Package Import Robot
  • Author(s): Otto Kekäläinen
  • Date: 2014-08-27 21:12:36 UTC
  • mfrom: (2.1.6 sid)
  • Revision ID: package-import@ubuntu.com-20140827211236-se41hwfe4xy0hpef
* d/control: Removed Provides: libmysqlclient-dev (Closes: #759309)
* d/control: Removed Provides: libmysqld-dev with same motivation
* Re-introduced tha HPPA build patch as the upstream fix wasn't complete
* Fixed all kFreeBSD build and test suite issues
* Added Italian translation (Closes: #759813)

Show diffs side-by-side

added added

removed removed

Lines of Context:
253
253
    return r;
254
254
}
255
255
 
 
256
static int
 
257
db_put(DB *db, DB_TXN *txn, DBT *key, DBT *val, int flags, bool do_log) {
 
258
    int r = 0;
 
259
    bool unique = false;
 
260
    enum ft_msg_type type = FT_INSERT;
 
261
    if (flags == DB_NOOVERWRITE) {
 
262
        unique = true;
 
263
    } else if (flags == DB_NOOVERWRITE_NO_ERROR) {
 
264
        type = FT_INSERT_NO_OVERWRITE;
 
265
    } else if (flags != 0) {
 
266
        // All other non-zero flags are unsupported
 
267
        r = EINVAL;
 
268
    }
 
269
    if (r == 0) {
 
270
        TOKUTXN ttxn = txn ? db_txn_struct_i(txn)->tokutxn : nullptr;
 
271
        if (unique) {
 
272
            r = toku_ft_insert_unique(db->i->ft_handle, key, val, ttxn, do_log);
 
273
        } else {
 
274
            toku_ft_maybe_insert(db->i->ft_handle, key, val, ttxn, false, ZERO_LSN, do_log, type);
 
275
        }
 
276
        invariant(r == DB_KEYEXIST || r == 0);
 
277
    }
 
278
    return r;
 
279
}
256
280
 
257
281
int
258
282
toku_db_put(DB *db, DB_TXN *txn, DBT *key, DBT *val, uint32_t flags, bool holds_mo_lock) {
265
289
    flags &= ~lock_flags;
266
290
 
267
291
    r = db_put_check_size_constraints(db, key, val);
268
 
    if (r == 0) {
269
 
        //Do any checking required by the flags.
270
 
        r = db_put_check_overwrite_constraint(db, txn, key, lock_flags, flags);
271
 
    }
272
 
    //Do locking if necessary. Do not grab the lock again if this DB had a unique
273
 
    //check performed because the lock was already grabbed by its cursor callback.
 
292
 
 
293
    //Do locking if necessary.
274
294
    bool do_locking = (bool)(db->i->lt && !(lock_flags&DB_PRELOCKED_WRITE));
275
 
    if (r == 0 && do_locking && !(flags & DB_NOOVERWRITE)) {
 
295
    if (r == 0 && do_locking) {
276
296
        r = toku_db_get_point_write_lock(db, txn, key);
277
297
    }
278
298
    if (r == 0) {
279
299
        //Insert into the ft.
280
 
        TOKUTXN ttxn = txn ? db_txn_struct_i(txn)->tokutxn : NULL;
281
 
        enum ft_msg_type type = FT_INSERT;
282
 
        if (flags==DB_NOOVERWRITE_NO_ERROR) {
283
 
            type = FT_INSERT_NO_OVERWRITE;
284
 
        }
285
300
        if (!holds_mo_lock) toku_multi_operation_client_lock();
286
 
        toku_ft_maybe_insert(db->i->ft_handle, key, val, ttxn, false, ZERO_LSN, true, type);
 
301
        r = db_put(db, txn, key, val, flags, true);
287
302
        if (!holds_mo_lock) toku_multi_operation_client_unlock();
288
303
    }
289
304
 
635
650
    }
636
651
}
637
652
 
 
653
// Requires: If remaining_flags is non-null, this function performs any required uniqueness checks
 
654
//           Otherwise, the caller is responsible.
638
655
static int
639
 
do_put_multiple(DB_TXN *txn, uint32_t num_dbs, DB *db_array[], DBT_ARRAY keys[], DBT_ARRAY vals[], DB *src_db, const DBT *src_key, bool indexer_shortcut) {
640
 
    TOKUTXN ttxn = db_txn_struct_i(txn)->tokutxn;
 
656
do_put_multiple(DB_TXN *txn, uint32_t num_dbs, DB *db_array[], DBT_ARRAY keys[], DBT_ARRAY vals[], uint32_t *remaining_flags, DB *src_db, const DBT *src_key, bool indexer_shortcut) {
 
657
    int r = 0;
641
658
    for (uint32_t which_db = 0; which_db < num_dbs; which_db++) {
642
659
        DB *db = db_array[which_db];
643
660
 
666
683
            }
667
684
            if (do_put) {
668
685
                for (uint32_t i = 0; i < keys[which_db].size; i++) {
669
 
                    // if db is being indexed by an indexer, then put into that db if the src key is to the left or equal to the
670
 
                    // indexers cursor.  we have to get the src_db from the indexer and find it in the db_array.
671
 
                    toku_ft_maybe_insert(db->i->ft_handle,
672
 
                                         &keys[which_db].dbts[i], &vals[which_db].dbts[i],
673
 
                                         ttxn, false, ZERO_LSN, false, FT_INSERT);
 
686
                    int flags = 0;
 
687
                    if (remaining_flags != nullptr) {
 
688
                        flags = remaining_flags[which_db];
 
689
                        invariant(!(flags & DB_NOOVERWRITE_NO_ERROR));
 
690
                    }
 
691
                    r = db_put(db, txn, &keys[which_db].dbts[i], &vals[which_db].dbts[i], flags, false);
 
692
                    if (r != 0) {
 
693
                        goto done;
 
694
                    }
674
695
                }
675
696
            }
676
697
        }
677
698
    }
678
 
    return 0;
 
699
done:
 
700
    return r;
679
701
}
680
702
 
681
703
static int
754
776
            r = db_put_check_size_constraints(db, &put_key, &put_val);
755
777
            if (r != 0) goto cleanup;
756
778
 
757
 
            //Check overwrite constraints
758
 
            r = db_put_check_overwrite_constraint(db, txn,
759
 
                                                  &put_key,
760
 
                                                  lock_flags[which_db], remaining_flags[which_db]);
761
 
            if (r != 0) goto cleanup;
762
779
            if (remaining_flags[which_db] == DB_NOOVERWRITE_NO_ERROR) {
763
780
                //put_multiple does not support delaying the no error, since we would
764
781
                //have to log the flag in the put_multiple.
765
782
                r = EINVAL; goto cleanup;
766
783
            }
767
784
 
768
 
            //Do locking if necessary. Do not grab the lock again if this DB had a unique
769
 
            //check performed because the lock was already grabbed by its cursor callback.
770
 
            if (db->i->lt && !(lock_flags[which_db] & DB_PRELOCKED_WRITE) && !(remaining_flags[which_db] & DB_NOOVERWRITE)) {
 
785
            //Do locking if necessary.
 
786
            if (db->i->lt && !(lock_flags[which_db] & DB_PRELOCKED_WRITE)) {
771
787
                //Needs locking
772
788
                r = toku_db_get_point_write_lock(db, txn, &put_key);
773
789
                if (r != 0) goto cleanup;
790
806
        }
791
807
    }
792
808
    toku_multi_operation_client_lock();
793
 
    log_put_multiple(txn, src_db, src_key, src_val, num_dbs, fts);
794
 
    r = do_put_multiple(txn, num_dbs, db_array, put_keys, put_vals, src_db, src_key, indexer_shortcut);
 
809
    r = do_put_multiple(txn, num_dbs, db_array, put_keys, put_vals, remaining_flags, src_db, src_key, indexer_shortcut);
 
810
    if (r == 0) {
 
811
        log_put_multiple(txn, src_db, src_key, src_val, num_dbs, fts);
 
812
    }
795
813
    toku_multi_operation_client_unlock();
796
814
    if (indexer_lock_taken) {
797
815
        toku_indexer_unlock(indexer);
1075
1093
            // recovery so we don't end up losing data.
1076
1094
            // So unlike env->put_multiple, we ONLY log a 'put_multiple' log entry.
1077
1095
            log_put_multiple(txn, src_db, new_src_key, new_src_data, n_put_dbs, put_fts);
1078
 
            r = do_put_multiple(txn, n_put_dbs, put_dbs, put_key_arrays, put_val_arrays, src_db, new_src_key, indexer_shortcut);
 
1096
            r = do_put_multiple(txn, n_put_dbs, put_dbs, put_key_arrays, put_val_arrays, nullptr, src_db, new_src_key, indexer_shortcut);
1079
1097
        }
1080
1098
        toku_multi_operation_client_unlock();
1081
1099
        if (indexer_lock_taken) {