@@ -414,7 +414,7 @@ PageNum RecordPageHandler::get_page_num() const
414
414
415
415
bool RecordPageHandler::is_full () const { return page_header_->record_num >= page_header_->record_capacity ; }
416
416
417
- RC PaxRecordPageHandler::insert_record (const char *data, RID *rid)
417
+ /* RC PaxRecordPageHandler::insert_record(const char *data, RID *rid)
418
418
{
419
419
// your code here
420
420
// exit(-1);
@@ -451,6 +451,43 @@ RC PaxRecordPageHandler::insert_record(const char *data, RID *rid)
451
451
rid->slot_num = index;
452
452
}
453
453
return RC::SUCCESS;
454
+ }*/
455
+ RC PaxRecordPageHandler::insert_record (const char *data, RID *rid)
456
+ {
457
+ // your code here
458
+ ASSERT (rw_mode_ != ReadWriteMode::READ_ONLY,
459
+ " cannot insert record into page while the page is readonly" );
460
+
461
+ if (page_header_->record_num == page_header_->record_capacity ) {
462
+ LOG_WARN (" Page is full, page_num %d:%d." , disk_buffer_pool_->file_desc (), frame_->page_num ());
463
+ return RC::RECORD_NOMEM;
464
+ }
465
+
466
+ // 找到空闲位置
467
+ Bitmap bitmap (bitmap_, page_header_->record_capacity );
468
+ int index = bitmap.next_unsetted_bit (0 );
469
+ bitmap.set_bit (index );
470
+ page_header_->record_num ++;
471
+
472
+ RC rc = log_handler_.insert_record (frame_, RID (get_page_num (), index ), data);
473
+ if (OB_FAIL (rc)) {
474
+ LOG_ERROR (" Failed to insert record. page_num %d:%d. rc=%s" , disk_buffer_pool_->file_desc (), frame_->page_num (), strrc (rc));
475
+ // return rc; // ignore errors
476
+ }
477
+ int offset = 0 ;
478
+ for (int i=0 ;i<page_header_->column_num ;i++)
479
+ {
480
+ char * _data = get_field_data (index ,i);
481
+ memcpy (_data,data+offset,get_field_len (i));
482
+ offset+=get_field_len (i);
483
+ }
484
+ frame_->mark_dirty ();
485
+ if (rid)
486
+ {
487
+ rid->page_num = get_page_num ();
488
+ rid->slot_num = index ;
489
+ }
490
+ return RC::SUCCESS;
454
491
}
455
492
456
493
RC PaxRecordPageHandler::delete_record (const RID *rid)
@@ -477,7 +514,7 @@ RC PaxRecordPageHandler::delete_record(const RID *rid)
477
514
}
478
515
}
479
516
480
- RC PaxRecordPageHandler::get_record (const RID &rid, Record &record)
517
+ /* RC PaxRecordPageHandler::get_record(const RID &rid, Record &record)
481
518
{
482
519
// your code here
483
520
// exit(-1);
@@ -504,6 +541,34 @@ RC PaxRecordPageHandler::get_record(const RID &rid, Record &record)
504
541
}
505
542
record.copy_data(data,page_header_->record_real_size);
506
543
return RC::SUCCESS;
544
+ }*/
545
+ RC PaxRecordPageHandler::get_record (const RID &rid, Record &record)
546
+ {
547
+ // your code here
548
+ if (rid.slot_num >= page_header_->record_capacity ) {
549
+ LOG_ERROR (" Invalid slot_num %d, exceed page's record capacity, frame=%s, page_header=%s" ,
550
+ rid.slot_num , frame_->to_string ().c_str (), page_header_->to_string ().c_str ());
551
+ return RC::RECORD_INVALID_RID;
552
+ }
553
+
554
+ Bitmap bitmap (bitmap_, page_header_->record_capacity );
555
+ if (!bitmap.get_bit (rid.slot_num )) {
556
+ LOG_ERROR (" Invalid slot_num:%d, slot is empty, page_num %d." , rid.slot_num , frame_->page_num ());
557
+ return RC::RECORD_NOT_EXIST;
558
+ }
559
+ record.set_rid (rid);
560
+
561
+ char * data = new char [page_header_->record_real_size ];
562
+ int offset = 0 ;
563
+ for (int i=0 ;i<page_header_->column_num ;i++)
564
+ {
565
+ char * _data = get_field_data (rid.slot_num ,i);
566
+ memcpy (data+offset,_data,get_field_len (i));
567
+ offset+=get_field_len (i);
568
+ }
569
+ record.copy_data (data,page_header_->record_real_size );
570
+ delete[] data;
571
+ return RC::SUCCESS;
507
572
}
508
573
/*
509
574
// TODO: specify the column_ids that chunk needed. currenly we get all columns
0 commit comments