@brief Open database-handler. IMPLEMENTATION Try O_RDONLY if cannot open as O_RDWR Don't wait for locks if not HA_OPEN_WAIT_IF_LOCKED is set */
| 3898 | Don't wait for locks if not HA_OPEN_WAIT_IF_LOCKED is set |
| 3899 | */ |
| 3900 | int handler::ha_open(TABLE *table_arg, const char *name, int mode, |
| 3901 | uint test_if_locked, MEM_ROOT *mem_root, |
| 3902 | List<String> *partitions_to_open) |
| 3903 | { |
| 3904 | int error; |
| 3905 | DBUG_ENTER("handler::ha_open"); |
| 3906 | DBUG_PRINT("enter", |
| 3907 | ("name: %s db_type: %d db_stat: %d mode: %d lock_test: %d", |
| 3908 | name, ht->db_type, table_arg->db_stat, mode, |
| 3909 | test_if_locked)); |
| 3910 | |
| 3911 | set_table(table_arg); |
| 3912 | DBUG_ASSERT(table->s == table_share); |
| 3913 | DBUG_ASSERT(m_lock_type == F_UNLCK); |
| 3914 | DBUG_PRINT("info", ("old m_lock_type: %d F_UNLCK %d", m_lock_type, F_UNLCK)); |
| 3915 | DBUG_ASSERT(alloc_root_inited(&table->mem_root)); |
| 3916 | |
| 3917 | set_partitions_to_open(partitions_to_open); |
| 3918 | internal_tmp_table= MY_TEST(test_if_locked & HA_OPEN_INTERNAL_TABLE); |
| 3919 | |
| 3920 | if (!internal_tmp_table && (test_if_locked & HA_OPEN_TMP_TABLE) && |
| 3921 | current_thd->slave_thread) |
| 3922 | { |
| 3923 | /* |
| 3924 | This is a temporary table used by replication that is not attached |
| 3925 | to a THD. Mark it as a global temporary table. |
| 3926 | */ |
| 3927 | test_if_locked|= HA_OPEN_GLOBAL_TMP_TABLE; |
| 3928 | } |
| 3929 | |
| 3930 | if (unlikely((error=open(name,mode,test_if_locked)))) |
| 3931 | { |
| 3932 | if ((error == EACCES || error == EROFS) && mode == O_RDWR && |
| 3933 | (table->db_stat & HA_TRY_READ_ONLY)) |
| 3934 | { |
| 3935 | table->db_stat|=HA_READ_ONLY; |
| 3936 | error=open(name,O_RDONLY,test_if_locked); |
| 3937 | } |
| 3938 | } |
| 3939 | if (unlikely(error)) |
| 3940 | { |
| 3941 | my_errno= error; /* Safeguard */ |
| 3942 | DBUG_PRINT("error",("error: %d errno: %d",error,errno)); |
| 3943 | } |
| 3944 | else |
| 3945 | { |
| 3946 | DBUG_ASSERT(m_psi == NULL); |
| 3947 | DBUG_ASSERT(table_share != NULL); |
| 3948 | /* |
| 3949 | Do not call this for partitions handlers, since it may take too much |
| 3950 | resources. |
| 3951 | So only use the m_psi on table level, not for individual partitions. |
| 3952 | */ |
| 3953 | if (!(test_if_locked & HA_OPEN_NO_PSI_CALL)) |
| 3954 | { |
| 3955 | m_psi= PSI_CALL_open_table(ha_table_share_psi(), this); |
| 3956 | } |
| 3957 |
no test coverage detected