Restarting a single node quickly - mariadb

I have a galera cluster comprised of 2 nodes (mariadb-1.test.com: 10.10.10.21, mariadb-2.test.com: 10.10.10.22) and an arbitrator on 3 different centos 8 servers.
Is it possible to restart a node without deleting /var/lib/mysql and/or using galera_new_cluster ?
Is it possible to restart a node differently than after a full cluster crash ?
[centos#mariadb-1 ~]$ sudo systemctl restart mariadb.service
Job for mariadb.service failed because a fatal signal was delivered to the control process.
See "systemctl status mariadb.service" and "journalctl -xe" for details.
[centos#mariadb-1 ~]$ sudo systemctl status mariadb.service
● mariadb.service - MariaDB 10.3 database server
Loaded: loaded (/usr/lib/systemd/system/mariadb.service; enabled; vendor preset: disabled)
Active: failed (Result: exit-code) since Thu 2021-12-16 00:07:08 CET; 29s ago
Docs: man:mysqld(8)
https://mariadb.com/kb/en/library/systemd/
Process: 9887 ExecStart=/usr/libexec/mysqld --basedir=/usr $MYSQLD_OPTS $_WSREP_NEW_CLUSTER (code=exited, status=1/FAILURE)
Process: 9849 ExecStartPre=/usr/libexec/mysql-prepare-db-dir mariadb.service (code=exited, status=0/SUCCESS)
Process: 9824 ExecStartPre=/usr/libexec/mysql-check-socket (code=exited, status=0/SUCCESS)
Main PID: 9887 (code=exited, status=1/FAILURE)
Status: "MariaDB server is down"
déc. 16 00:06:36 mariadb-1.test.com systemd[1]: Starting MariaDB 10.3 database server...
déc. 16 00:06:36 mariadb-1.test.com mysql-prepare-db-dir[9849]: Database MariaDB is probably initialized in /var/lib/mysql already, nothing is done.
déc. 16 00:06:36 mariadb-1.test.com mysql-prepare-db-dir[9849]: If this is not the case, make sure the /var/lib/mysql is empty before running mysql-prepare-db-dir.
déc. 16 00:06:36 mariadb-1.test.com mysqld[9887]: 2021-12-16 0:06:36 0 [Note] /usr/libexec/mysqld (mysqld 10.3.28-MariaDB) starting as process 9887 ...
déc. 16 00:07:08 mariadb-1.test.com systemd[1]: mariadb.service: Main process exited, code=exited, status=1/FAILURE
déc. 16 00:07:08 mariadb-1.test.com systemd[1]: mariadb.service: Failed with result 'exit-code'.
déc. 16 00:07:08 mariadb-1.test.com systemd[1]: Failed to start MariaDB 10.3 database server.
journalctl -xe does not give more details.
/var/log/mariadb/mariadb.log contents on the node after a failed restart:
2021-12-16 0:14:43 0 [Note] WSREP: Read nil XID from storage engines, skipping position init
2021-12-16 0:14:43 0 [Note] WSREP: wsrep_load(): loading provider library '/usr/lib64/galera/libgalera_smm.so'
2021-12-16 0:14:43 0 [Note] WSREP: wsrep_load(): Galera 3.32(rXXXX) by Codership Oy <info#codership.com> loaded successfully.
2021-12-16 0:14:43 0 [Note] WSREP: CRC-32C: using 64-bit x86 acceleration.
2021-12-16 0:14:43 0 [Note] WSREP: Found saved state: 00000000-0000-0000-0000-000000000000:-1, safe_to_bootstrap: 0
2021-12-16 0:14:43 0 [Note] WSREP: Passing config to GCS: base_dir = /var/lib/mysql/; base_host = 10.10.10.21; base_port = 4567; cert.log_conflicts = no; cert.optimistic_pa = yes; debug = no; evs.auto_evict = 0; evs.delay_margin = PT1S; evs.delayed_keep_period = PT30S; evs.inactive_check_period = PT0.5S; evs.inactive_timeout = PT15S; evs.join_retrans_period = PT1S; evs.max_install_timeouts = 3; evs.send_window = 4; evs.stats_report_period = PT1M; evs.suspect_timeout = PT5S; evs.user_send_window = 2; evs.view_forget_timeout = PT24H; gcache.dir = /var/lib/mysql/; gcache.keep_pages_size = 0; gcache.mem_size = 0; gcache.name = /var/lib/mysql//galera.cache; gcache.page_size = 128M; gcache.recover = no; gcache.size = 128M; gcomm.thread_prio = ; gcs.fc_debug = 0; gcs.fc_factor = 1.0; gcs.fc_limit = 16; gcs.fc_master_slave = no; gcs.max_packet_size = 64500; gcs.max_throttle = 0.25; gcs.recv_q_hard_limit = 9223372036854775807; gcs.recv_q_soft_limit = 0.25; gcs.sync_donor = no; gmcast.segment = 0; gmcast.version = 0; pc.announce_timeout = PT3S;
2021-12-16 0:14:43 0 [Note] WSREP: GCache history reset: 00000000-0000-0000-0000-000000000000:0 -> 00000000-0000-0000-0000-000000000000:-1
2021-12-16 0:14:43 0 [Note] WSREP: Assign initial position for certification: -1, protocol version: -1
2021-12-16 0:14:43 0 [Note] WSREP: wsrep_sst_grab()
2021-12-16 0:14:43 0 [Note] WSREP: Start replication
2021-12-16 0:14:43 0 [Note] WSREP: Setting initial position to 00000000-0000-0000-0000-000000000000:-1
2021-12-16 0:14:43 0 [Note] WSREP: protonet asio version 0
2021-12-16 0:14:43 0 [Note] WSREP: Using CRC-32C for message checksums.
2021-12-16 0:14:43 0 [Note] WSREP: backend: asio
2021-12-16 0:14:43 0 [Note] WSREP: gcomm thread scheduling priority set to other:0
2021-12-16 0:14:43 0 [Warning] WSREP: access file(/var/lib/mysql//gvwstate.dat) failed(No such file or directory)
2021-12-16 0:14:43 0 [Note] WSREP: restore pc from disk failed
2021-12-16 0:14:43 0 [Note] WSREP: GMCast version 0
2021-12-16 0:14:43 0 [Note] WSREP: (c96725c5, 'tcp://0.0.0.0:4567') listening at tcp://0.0.0.0:4567
2021-12-16 0:14:43 0 [Note] WSREP: (c96725c5, 'tcp://0.0.0.0:4567') multicast: , ttl: 1
2021-12-16 0:14:43 0 [Note] WSREP: EVS version 0
2021-12-16 0:14:43 0 [Note] WSREP: gcomm: connecting to group 'test-wsrep', peer '10.10.10.21:,10.10.10.22:'
2021-12-16 0:14:43 0 [Note] WSREP: (c96725c5, 'tcp://0.0.0.0:4567') Found matching local endpoint for a connection, blacklisting address tcp://10.10.10.21:4567
2021-12-16 0:14:43 0 [Note] WSREP: (c96725c5, 'tcp://0.0.0.0:4567') connection established to 3cfd9c42 tcp://10.10.10.22:4567
2021-12-16 0:14:43 0 [Note] WSREP: (c96725c5, 'tcp://0.0.0.0:4567') turning message relay requesting on, nonlive peers: tcp://10.10.10.30:4567
2021-12-16 0:14:43 0 [Note] WSREP: (c96725c5, 'tcp://0.0.0.0:4567') connection established to 34bdff1b tcp://10.10.10.30:4567
2021-12-16 0:14:43 0 [Note] WSREP: declaring 34bdff1b at tcp://10.10.10.30:4567 stable
2021-12-16 0:14:43 0 [Note] WSREP: declaring 3cfd9c42 at tcp://10.10.10.22:4567 stable
2021-12-16 0:14:43 0 [Note] WSREP: Node 34bdff1b state prim
2021-12-16 0:14:43 0 [Note] WSREP: view(view_id(PRIM,34bdff1b,340) memb {
34bdff1b,0
3cfd9c42,0
c96725c5,0
} joined {
} left {
} partitioned {
})
2021-12-16 0:14:43 0 [Note] WSREP: save pc into disk
2021-12-16 0:14:44 0 [Note] WSREP: gcomm: connected
2021-12-16 0:14:44 0 [Note] WSREP: Changing maximum packet size to 64500, resulting msg size: 32636
2021-12-16 0:14:44 0 [Note] WSREP: Shifting CLOSED -> OPEN (TO: 0)
2021-12-16 0:14:44 0 [Note] WSREP: Opened channel 'test-wsrep'
2021-12-16 0:14:44 0 [Note] WSREP: New COMPONENT: primary = yes, bootstrap = no, my_idx = 2, memb_num = 3
2021-12-16 0:14:44 0 [Note] WSREP: Waiting for SST to complete.
2021-12-16 0:14:44 0 [Note] WSREP: STATE EXCHANGE: Waiting for state UUID.
2021-12-16 0:14:44 0 [Note] WSREP: STATE EXCHANGE: sent state msg: c9b97488-5dfc-11ec-a809-f37d727cc3ec
2021-12-16 0:14:44 0 [Note] WSREP: STATE EXCHANGE: got state msg: c9b97488-5dfc-11ec-a809-f37d727cc3ec from 0 (garb)
2021-12-16 0:14:44 0 [Note] WSREP: STATE EXCHANGE: got state msg: c9b97488-5dfc-11ec-a809-f37d727cc3ec from 1 (mariadb-2.test.com)
2021-12-16 0:14:44 0 [Note] WSREP: STATE EXCHANGE: got state msg: c9b97488-5dfc-11ec-a809-f37d727cc3ec from 2 (mariadb-1.test.com)
2021-12-16 0:14:44 0 [Note] WSREP: Quorum results:
version = 4,
component = PRIMARY,
conf_id = 289,
members = 2/3 (joined/total),
act_id = 66241951,
last_appl. = -1,
protocols = 0/9/3 (gcs/repl/appl),
group UUID = 52e841e5-398a-11eb-8a1c-8efbc5e6d73d
2021-12-16 0:14:44 0 [Note] WSREP: Flow-control interval: [28, 28]
2021-12-16 0:14:44 0 [Note] WSREP: Shifting OPEN -> PRIMARY (TO: 66241951)
2021-12-16 0:14:44 2 [Note] WSREP: State transfer required:
Group state: 52e841e5-398a-11eb-8a1c-8efbc5e6d73d:66241951
Local state: 00000000-0000-0000-0000-000000000000:-1
2021-12-16 0:14:44 2 [Note] WSREP: REPL Protocols: 9 (4, 2)
2021-12-16 0:14:44 2 [Note] WSREP: New cluster view: global state: 52e841e5-398a-11eb-8a1c-8efbc5e6d73d:66241951, view# 290: Primary, number of nodes: 3, my index: 2, protocol version 3
2021-12-16 0:14:44 2 [Warning] WSREP: Gap in state sequence. Need state transfer.
2021-12-16 0:14:44 0 [Note] WSREP: Running: 'wsrep_sst_rsync --role 'joiner' --address '10.10.10.21' --datadir '/var/lib/mysql/' --parent '10502' --mysqld-args --basedir=/usr'
2021-12-16 0:14:44 2 [Note] WSREP: Prepared SST request: rsync|10.10.10.21:4444/rsync_sst
2021-12-16 0:14:44 2 [Note] WSREP: wsrep_notify_cmd is not defined, skipping notification.
2021-12-16 0:14:44 2 [Note] WSREP: Assign initial position for certification: 66241951, protocol version: 4
2021-12-16 0:14:44 0 [Note] WSREP: Service thread queue flushed.
2021-12-16 0:14:44 2 [Warning] WSREP: Failed to prepare for incremental state transfer: Local state UUID (00000000-0000-0000-0000-000000000000) does not match group state UUID (52e841e5-398a-11eb-8a1c-8efbc5e6d73d): 1 (Operation not permitted)
at galera/src/replicator_str.cpp:prepare_for_IST():467. IST will be unavailable.
2021-12-16 0:14:44 0 [Note] WSREP: Member 2.0 (mariadb-1.test.com) requested state transfer from '*any*'. Selected 1.0 (mariadb-2.test.com)(SYNCED) as donor.
2021-12-16 0:14:44 0 [Note] WSREP: Shifting PRIMARY -> JOINER (TO: 66241951)
2021-12-16 0:14:44 2 [Note] WSREP: Requesting state transfer: success, donor: 1
2021-12-16 0:14:44 2 [Note] WSREP: GCache history reset: 00000000-0000-0000-0000-000000000000:0 -> 52e841e5-398a-11eb-8a1c-8efbc5e6d73d:66241951
2021-12-16 0:14:44 0 [Warning] WSREP: 1.0 (mariadb-2.test.com): State transfer to 2.0 (mariadb-1.test.com) failed: -255 (Unknown error 255)
2021-12-16 0:14:44 0 [ERROR] WSREP: gcs/src/gcs_group.cpp:gcs_group_handle_join_msg():780: Will never receive state. Need to abort.
2021-12-16 0:14:44 0 [Note] WSREP: gcomm: terminating thread
2021-12-16 0:14:44 0 [Note] WSREP: gcomm: joining thread
2021-12-16 0:14:44 0 [Note] WSREP: gcomm: closing backend
2021-12-16 0:14:45 0 [Note] WSREP: view(view_id(NON_PRIM,34bdff1b,340) memb {
c96725c5,0
} joined {
} left {
} partitioned {
34bdff1b,0
3cfd9c42,0
})
2021-12-16 0:14:45 0 [Note] WSREP: view((empty))
2021-12-16 0:14:45 0 [Note] WSREP: gcomm: closed
2021-12-16 0:14:45 0 [Note] WSREP: /usr/libexec/mysqld: Terminated.
WSREP_SST: [ERROR] Parent mysqld process (PID:10502) terminated unexpectedly. (20211216 00:14:46.490)
WSREP_SST: [INFO] Joiner cleanup. rsync PID: 10560 (20211216 00:14:46.491)
WSREP_SST: [INFO] Joiner cleanup done. (20211216 00:14:46.996)
[centos#mariadb-1 ~]$
The node that remains in the cluster seems fine:
MariaDB [(none)]> SHOW GLOBAL STATUS LIKE 'wsrep_%' ;
+-------------------------------+--------------------------------------+
| Variable_name | Value |
+-------------------------------+--------------------------------------+
| wsrep_applier_thread_count | 1 |
| wsrep_apply_oooe | 0.000220 |
| wsrep_apply_oool | 0.000000 |
| wsrep_apply_window | 1.000220 |
| wsrep_causal_reads | 0 |
| wsrep_cert_deps_distance | 3770.895462 |
| wsrep_cert_index_size | 69 |
| wsrep_cert_interval | 0.091845 |
| wsrep_cluster_conf_id | 268 |
| wsrep_cluster_size | 2 |
| wsrep_cluster_state_uuid | 52e841e5-398a-11eb-8a1c-8efbc5e6d73d |
| wsrep_cluster_status | Primary |
| wsrep_cluster_weight | 2 |
| wsrep_commit_oooe | 0.000000 |
| wsrep_commit_oool | 0.000000 |
| wsrep_commit_window | 1.000000 |
| wsrep_connected | ON |
| wsrep_desync_count | 0 |
| wsrep_evs_delayed | |
| wsrep_evs_evict_list | |
| wsrep_evs_repl_latency | 0/0/0/0/0 |
| wsrep_evs_state | OPERATIONAL |
| wsrep_flow_control_active | false |
| wsrep_flow_control_paused | 0.000000 |
| wsrep_flow_control_paused_ns | 3297992241 |
| wsrep_flow_control_recv | 9 |
| wsrep_flow_control_requested | false |
| wsrep_flow_control_sent | 9 |
| wsrep_gcomm_uuid | 3cfd9c42-e33a-11eb-aea6-1fc34d7a6b30 |
| wsrep_gmcast_segment | 0 |
| wsrep_incoming_addresses | ,10.10.10.22:3306 |
| wsrep_last_committed | 66241750 |
| wsrep_local_bf_aborts | 0 |
| wsrep_local_cached_downto | 66130787 |
| wsrep_local_cert_failures | 0 |
| wsrep_local_commits | 116324 |
| wsrep_local_index | 1 |
| wsrep_local_recv_queue | 0 |
| wsrep_local_recv_queue_avg | 0.006762 |
| wsrep_local_recv_queue_max | 31 |
| wsrep_local_recv_queue_min | 0 |
| wsrep_local_replays | 0 |
| wsrep_local_send_queue | 0 |
| wsrep_local_send_queue_avg | 0.000003 |
| wsrep_local_send_queue_max | 2 |
| wsrep_local_send_queue_min | 0 |
| wsrep_local_state | 4 |
| wsrep_local_state_comment | Synced |
| wsrep_local_state_uuid | 52e841e5-398a-11eb-8a1c-8efbc5e6d73d |
| wsrep_open_connections | 0 |
| wsrep_open_transactions | 0 |
| wsrep_protocol_version | 9 |
| wsrep_provider_name | Galera |
| wsrep_provider_vendor | Codership Oy <info#codership.com> |
| wsrep_provider_version | 3.32(rXXXX) |
| wsrep_ready | ON |
| wsrep_received | 26471367 |
| wsrep_received_bytes | 30177334116 |
| wsrep_repl_data_bytes | 91246197 |
| wsrep_repl_keys | 9616150 |
| wsrep_repl_keys_bytes | 79743208 |
| wsrep_repl_other_bytes | 0 |
| wsrep_replicated | 117234 |
| wsrep_replicated_bytes | 2538681128 |
| wsrep_rollbacker_thread_count | 1 |
| wsrep_thread_count | 2 |
+-------------------------------+--------------------------------------+
Thanks.

Problem solved : the state snapshot transfer method was rsync and I had a directory in /var/lib/mysql on the receiver node, which mysql didn't have write access to. I removed the directory and the node restarted successfully.

Related

Wrong cinder quota usage calculation - BUG

I am facing the issue with cinder volume usage calculation, you can see from the below output that the 10GB volume is in reserved status and total usage is not included this 10Gb. Is there anyway to clear this or update In_use, out actual usage is 67GB but cinder usage showing only 57GB and remaining marked as Reserved.
cinder quota-usage 82eaddf1f348142cabbed0d2ff7e213a0
+----------------------+--------+----------+-------+
| Type | In_use | Reserved | Limit |
+----------------------+--------+----------+-------+
| backup_gigabytes | 0 | 0 | 1000 |
| backups | 0 | 0 | 10 |
| gigabytes | 57 | 10 | 1000 |
| gigabytes_Local | 57 | 10 | 1000 |
| per_volume_gigabytes | 0 | 0 | -1 |
| snapshots | 0 | 0 | 10 |
| snapshots_Local | 0 | 0 | -1 |
| volumes | 6 | 1 | 10 |
| volumes_Local | 6 | 1 | -1 |
+----------------------+--------+----------+-------+
This seems to be a bug, it has been reported under https://bugzilla.redhat.com/show_bug.cgi?id=1515576

Do Timestamp operations work on UNIX_TIMESTAMP or Visual Representation of Timestamp

I read this and As per MySQL documentation for Timestamp:
It can hold values starting at '1970-01-01 00:00:01' (UTC) to
'2038-01-19 05:14:07' (UTC) . This range is caused by MariaDB storing
the TIMESTAMP values as the number of seconds since '1970-01-01
00:00:00' (UTC).
so all the timestamp related operations are done in UNIX_TIMESTAMP as there is no timezone info stored in timestamp. That was my understanding.
My current time zone: IST (+05:30)
After midnight, when date changed in IST but not in UTC I did an insert operation. I thought if I do a DATE(now()) for IST it should show the yesterday's stored record as I thought UNIX_TIMESTAMP will be used for timestamp comparison which will remain same.
In below code block you can see the timezone offset as +05:30 which is for IST. Record against ID = 5 was inserted at 13th Feb,2017 00:04 pm. But in UTC_STAMP would have been somewhere 12th Feb,2017 18hr34min(5hr30min back). So date is not changed in UTC. I did a select statement for date = 13th Feb 2017, I thought I would I get (1,2,3,5) records as result because UTC representation of 13th Feb 2017,00:00 in IST still falls under UTC date of 12thFeb,2017 . But I got only record against ID = 5.
Q.1
In short I was thinking that value = 2017-02-13 will be converted to UNIX_TIMESTAMP(a numerical value) and then comparison occurs. What I am missing ? or else mention the steps taken by db to generate the below result ? I hope I was able explain myself.
Q.2 How does java.sql.Timestamp executes ? It works something like mentioned in code block or it first converts timestamp values to unix_timestamp and then do the conversion or is it database internal implementation compares long values of timestamp ?
MariaDB [test]>SELECT ##global.time_zone, ##session.time_zone;
+--------------------+---------------------+
| ##global.time_zone | ##session.time_zone |
+--------------------+---------------------+
| SYSTEM | +05:30 |
+--------------------+---------------------+
MariaDB [test]> desc t;
+-------+-----------+------+-----+-------------------+---------------- -------------+
| Field | Type | Null | Key | Default | Extra |
+-------+-----------+------+-----+-------------------+-----------------------------+
| id | int(11) | YES | | NULL | |
| ts | timestamp | NO | | CURRENT_TIMESTAMP | on update CURRENT_TIMESTAMP |
+-------+-----------+------+-----+-------------------+--------------- --------------+
MariaDB [test]> select * from t;
+------+---------------------+
| id | ts |
+------+---------------------+
| 1 | 2017-02-12 22:10:35 |
| 2 | 2017-02-12 22:10:35 |
| 3 | 2017-02-12 22:13:06 |
| 4 | 2001-07-22 12:12:12 |
| 5 | 2017-02-13 00:04:01 |
+------+---------------------+
MariaDB [test]> select * from t where date(ts) = '2017-02-13';
+------+---------------------+
| id | ts |
+------+---------------------+
| 5 | 2017-02-13 00:04:01 |
+------+---------------------+
MariaDB [test]> set time_zone = '+00:00';
MariaDB [test]> SELECT ##global.time_zone, ##session.time_zone;
+--------------------+---------------------+
| ##global.time_zone | ##session.time_zone |
+--------------------+---------------------+
| SYSTEM | +00:00 |
+--------------------+---------------------+
MariaDB [test]> select * from t;
+------+---------------------+
| id | ts |
+------+---------------------+
| 1 | 2017-02-12 16:40:35 |
| 2 | 2017-02-12 16:40:35 |
| 3 | 2017-02-12 16:43:06 |
| 4 | 2001-07-22 06:42:12 |
| 5 | 2017-02-12 18:34:01 |
+------+---------------------+
MariaDB [test]> select * from t where date(ts) = '2017-02-12';
+------+---------------------+
| id | ts |
+------+---------------------+
| 1 | 2017-02-12 16:40:35 |
| 2 | 2017-02-12 16:40:35 |
| 3 | 2017-02-12 16:43:06 |
| 5 | 2017-02-12 18:34:01 |
+------+---------------------+
EDIT1: I tried using database server with UTC timezone and IST as application server. After midnight, when IST changed its date and UTC didn't- I repeated the insert and create operations as mentioned above.Below are the records and info:
MariaDB [test]> SELECT ##global.time_zone, ##session.time_zone;
+--------------------+---------------------+
| ##global.time_zone | ##session.time_zone |
+--------------------+---------------------+
| UTC | UTC |
+--------------------+---------------------+
1 row in set (0.30 sec)
MariaDB [test]> select * from t ;
+----+---------------------+
| id | ts |
+----+---------------------+
| 1 | 2017-02-13 19:22:15 |
| 2 | 2017-02-13 19:22:15 |
| 3 | 2017-02-13 19:21:40 |
| 4 | 2001-07-22 12:12:12 |
| 5 | 2017-02-14 00:56:13 |
+----+---------------------+
5 rows in set (0.40 sec)
MariaDB [test]> select UTC_TIMESTAMP;
+---------------------+
| UTC_TIMESTAMP |
+---------------------+
| 2017-02-13 19:21:22 |
+---------------------+
1 row in set (0.38 sec)
And used JDBC, to get the response:
SELECT * FROM t WHERE date(ts) = date(:currentDate);
where, currentDate = Timestamp.from(Instant.now()); from Java
Response was:
[
{
"id": 1,
"timestamp1": 1486993935000
},
{
"id": 2,
"timestamp1": 1486993935000
},
{
"id": 3,
"timestamp1": 1486993900000
}
]
why record(id=5) did not came ? Doesn't it mean that it looks for Visual Representation rather than extract date from UTC_TIMESTAMP numerical value if it would have done that it would have fetched record with id = 5.

Error in data frame, replacement has xx, data has xx

I hope someone can help with this problem - I have been chewing over it for a few hours now!
I have a data frame called 'journeys' as follows which shows a customer ID, their date of travel, mode and journey start time:
ID | Date | Mode | Time
------ | --------- | ------- | -----
1234 | 12/10/16 | Bus | 120
1234 | 12/10/16 | Bus | 130
1234 | 12/10/16 | Bus | 290
1234 | 12/10/16 | Train | 310
1234 | 12/10/16 | Bus | 330
4567 | 12/10/16 | Bus | 220
4567 | 12/10/16 | Tram | 230
4567 | 13/10/16 | Bus | 290
4567 | 13/10/16 | Bus | 450
4567 | 14/10/16 | Train | 1000
So on 12/10, customer 1234 made 4 bus jnys and 1 train jny.
I have written a basic loop in r to create a 5th column which identifies if the journey stages are linked i.e. the 2nd journey linked to the 1st journey, the 3rd journey linked to the 2nd journey (where 1=linked, 0=not linked), based on the following conditions:
the jnys are for the same person and take place on the same day
2 bus journeys/2 tram jnys/a bus and tram jny/a tram and bus jny are within 60 mins of one another (so a bus and train journey within 60 mins of one another would not be linked). The code is as follows:
df <- read.table("Journeys.txt", header=TRUE, sep=",")
for (i in 2:dim(df)[1]) {
if ((df$ID[i]==df$ID[i-1])
& (df$Date[i]==df$Date[i-1])
& ((df$Mode[i]=='Bus' & df$Mode[i-1]=='Bus')|
(df$Mode[i]=='Bus' & df$Mode[i-1]=='Tram')|
(df$Mode[i]=='Tram' & df$Mode[i-1]=='Bus')|
(df$Mode[i]=='Tram' & df$Mode[i-1]=='Tram'))
& (df$Time[i]-df$Time[i-1]<60))
{df$linked[i] <- 1}
else {df$linked[i] <- 0}
This should give me the following output:
ID | Date | Mode | Time | Linked
------ | --------- | ------- | ----- | -----
1234 | 12/10/16 | Bus | 120 | 0
1234 | 12/10/16 | Bus | 130 | 1
1234 | 12/10/16 | Bus | 290 | 0
1234 | 12/10/16 | Train | 310 | 0
1234 | 12/10/16 | Bus | 330 | 0
4567 | 12/10/16 | Bus | 220 | 0
4567 | 12/10/16 | Tram | 230 | 1
4567 | 13/10/16 | Bus | 290 | 0
4567 | 13/10/16 | Bus | 450 | 0
4567 | 14/10/16 | Train | 1000 | 0
However, when I try to run this I keep getting the following error message:
Error in $<-.data.frame(tmp, "linked", value = c(NA, 1)) :
replacement has 2 rows, data has 52231
When I ran this on a test dataset of about 150 rows, I didn't get this error message. I know it's related to the linked column, but I don't fully understand how to resolve it.
I use the same data as you, and it was working with your code (copy paste it) but the first row. you need to initialized it. df$linked[1] <- 0
Here a better use of the if and the condition (faster to read and faster to process for R).
I also add in comment (cat(i)), if you uncomment it, it is helpfull to see what is happening in the loop.
Last thing, I think you are expecting a 0 and not a 1 for the 8th row, as this is not the same day...
df<- read.csv("train.csv", sep=",")
df$linked <- 0
for (i in 2:dim(df)[1]) {
if (df$ID[i]==df$ID[i-1]) {
#cat(i)
if (df$Date[i]==df$Date[i-1]){
#cat(i)
if (df$Time[i]-df$Time[i-1]<60) {
#cat(i)
if (df$Mode[i]=="Bus" & df$Mode[i-1] %in% c("Bus", "Tram")) {
#cat(i)
df$linked[i] <- 1
} else {
if (df$Mode[i]=="Tram" & df$Mode[i-1] %in% c("Bus", "Tram")) {
df$linked[i] <- 1
#cat(i)
}
}
}
}
}
}
ID Date Mode Time linked
1 1234 12/10/2016 Bus 120 0
2 1234 12/10/2016 Bus 130 1
3 1234 12/10/2016 Bus 290 0
4 1234 12/10/2016 Train 310 0
5 1234 12/10/2016 Bus 330 0
6 4567 12/10/2016 Bus 220 0
7 4567 12/10/2016 Tram 230 1
8 4567 13/10/2016 Bus 290 0
9 4567 13/10/2016 Bus 450 0
10 4567 14/10/2016 Train 1000 0

Issues with Apache ServiceMix and javax.transaction

I am having an issue with Apache ServiceMix (7.0.0.M1). I start up a fresh service mix (clean) and simply install the transaction feature:
karaf#root>feature:install transaction
This puts the Aries Transaction Blueprint into a GracePeriod:
224 | GracePeriod | 80 | 1.1.1 | Apache Aries Transaction Blueprint
225 | GracePeriod | 80 | 2.1.0 | Apache Aries Transaction Blueprint
This keeps my apps I install later that require the javax transaction api from starting. Is there a workaround for this issue? I had the same issues when just using karaf 4.0.3 and trying to instal camel and transaction.
Below you'll find a listing of all bundles (the basic service mix + those added by installing the transaction feature above). Notice the failure due to the GracePeriod timeout.
karaf#root>list
START LEVEL 100 , List Threshold: 50
ID | State | Lvl | Version | Name
-------------------------------------------------------------------------------------------------------
10 | Active | 50 | 5.13.0 | activemq-karaf
11 | Active | 50 | 2.6.3 | Jackson-annotations
12 | Active | 50 | 2.6.3 | Jackson-core
13 | Active | 50 | 2.6.3 | jackson-databind
23 | Active | 50 | 3.1.4 | activeio-core
24 | Active | 50 | 5.13.0 | activemq-camel
25 | Active | 50 | 5.13.0 | activemq-osgi
40 | Active | 50 | 2.16.2 | camel-blueprint
41 | Active | 50 | 2.16.2 | camel-catalog
42 | Active | 80 | 2.16.2 | camel-commands-core
43 | Active | 50 | 2.16.2 | camel-core
44 | Active | 50 | 2.16.2 | camel-cxf
45 | Active | 50 | 2.16.2 | camel-cxf-transport
46 | Active | 50 | 2.16.2 | camel-jms
47 | Active | 50 | 2.16.2 | camel-spring
48 | Active | 50 | 2.16.2 | camel-xstream
49 | Active | 80 | 2.16.2 | camel-karaf-commands
51 | Active | 50 | 3.2.2 | Apache Commons Collections
53 | Active | 50 | 3.3.0 | Commons Net
54 | Active | 50 | 1.6.0 | Commons Pool
55 | Active | 50 | 2.4.2 | Apache Commons Pool
93 | Active | 50 | 2.0.0 | geronimo-j2ee-connector_1.5_spec
94 | Active | 50 | 1.0.1 | geronimo-j2ee-management_1.1_spec
99 | Active | 50 | 3.4.6 | ZooKeeper Bundle
129 | Active | 80 | 2.0.9 | Apache MINA Core
132 | Active | 50 | 7.0.0.M1 | Apache ServiceMix :: ActiveMQ :: Camel
133 | Active | 50 | 7.0.0.M1 | Apache ServiceMix :: ActiveMQ :: Service
136 | Active | 50 | 1.6.1.5 | Apache ServiceMix :: Bundles :: dom4j
138 | Active | 50 | 1.9.2.1 | Apache ServiceMix :: Bundles :: jasypt
142 | Active | 50 | 1.1.0.4 | Apache ServiceMix :: Bundles :: jdom
143 | Active | 50 | 2.3.0.2 | Apache ServiceMix :: Bundles :: kxml2
156 | Active | 50 | 1.7.0.6 | Apache ServiceMix :: Bundles :: velocity
160 | Active | 50 | 1.1.4.c | Apache ServiceMix :: Bundles :: xpp3
161 | Active | 50 | 1.4.8.1 | Apache ServiceMix :: Bundles :: xstream
172 | Active | 50 | 3.18.0 | Apache XBean :: Spring
201 | Active | 50 | 0.6.4 | JAXB2 Basics - Runtime
214 | Active | 50 | 2.11.0.v20140415-163722-cac6383e66 | Scala Standard Library
221 | Active | 80 | 1.2.0 | CDI APIs
222 | Active | 80 | 1.2 | javax.interceptor API
223 | Active | 80 | 1.2 | javax.transaction API
224 | Failure | 80 | 1.1.1 | Apache Aries Transaction Blueprint
225 | Failure | 80 | 2.1.0 | Apache Aries Transaction Blueprint
226 | Active | 80 | 1.3.0 | Apache Aries Transaction Manager
227 | Active | 80 | 1.0.2 | Apache Felix Coordinator Service
228 | Active | 80 | 1.0.0.2 | Apache ServiceMix :: Bundles :: javax.inject
I have cross posted to the apache mailing lists as well.
The problem is that the spring-tx feature installs the jta 1.1 spec bundle. The aries transaction bundles require the new jta 1.2 spec though. So they do not find the TransactionManager which is bound to the wrong spec version.
This is caused by an error in the karaf spring-tx feature. The feature should depend on the jta 1.1 spec with dependency=true. This allows the karaf resolver to choose a different bundle providing suitable capabilities.
I have documented this issue in KARAF-4358. The issues is solved on master and the 4.0.x branch. So it will be delivered in karaf 4.0.5. You can fix you karaf distro by editing the feature file in the system dir in the same way I did.

What control MPI_Barrier time to execute

This code:
#include <mpi.h>
int main(int argc, char* argv[])
{
MPI_Init(&argc, &argv);
for (unsigned int iter = 0 ; iter < 1000 ; iter++)
MPI_Barrier(MPI_COMM_WORLD);
MPI_Finalize();
return 0;
}
is very long to run with MPICH 3.1.4. Here are the wall clock (in seconds) for different MPI implementations.
On a laptop with 4 processors of 2 cpu cores:
| MPI size | MPICH 1.4.1p1 | openmpi 1.8.4 | MPICH 3.1.4 |
|----------|---------------|---------------|-------------|
| 2 | 0.01 | 0.39 | 0.01 |
| 4 | 0.02 | 0.39 | 0.01 |
| 8 | 0.14 | 0.45 | 27.28 |
| 16 | 0.34 | 0.53 | 71.56 |
On a desktop with 8 processors of 4 cpu cores:
| MPI size | MPICH 1.4.1p1 | openmpi 1.8.4 | MPICH 3.1.4 |
|----------|---------------|---------------|-------------|
| 2 | 0.00 | 0.41 | 0.00 |
| 4 | 0.01 | 0.41 | 0.01 |
| 8 | 0.07 | 0.45 | 2.57 |
| 16 | 0.36 | 0.54 | 61.76 |
What explain such a difference, and how to control it?
You are using MPI size > number of processors available. As MPI programs spawn in such a way that each process is handled by a single processor, what this means is that, for example when you run MPI size == 16 on your 8 core machine, each processor will be responsible for two processes; this will not make the program any faster, and, in fact, will make it slower as you have seen. The way to get around it is to either get a machine with more processors available, or to ensure that you run your code with MPI size <= number of processors available.

Resources