Project

General

Profile

TasksTasksNITBAsyncDatabase » History » Version 2

Anonymous, 02/19/2016 10:48 PM

1 1
2
3 2
h2. NITB asynchronous database access 
4
5
6 1
||Mentor ||Holger Freyther  ||
7
||Skills ||C  ||
8
||Length ||10 days  ||
9
10
11 2
h3. Goal
12 1
13 2
The osmo-nitb application is using the libdbi for database access. libdbis offers the usage of a variety of different backends and currently only the sqlite3 backend is used. In order to be able to use the [[MySQL]], Postgres or any other database there is some cleanup required. There is the need for some minor schema modifications to work on other databases but there is one more fundamental change. With SQLite3 the database is always local and the access is reasonable fast, when moving to [[MySQL]]/Postgres the database server might not be located on the same machine and access time might be slower. This is a problem because osmo-nitb is using the database synchronously.
14
15
16
h2. Approach
17
18
Our database code is wrapped inside the 'db' module, the code can be found in src/libmsc/db.c and the code and the callers need to be changed to perform the database lookup in an asynchronous way. This means a function like _db_get_subscriber_ may not return a _struct gsm_subscriber_ immediately but it needs to call a callback once the subscriber has been loaded. This also requires the modification of all callers of this method. This means a function that used to do this:
19
20
<pre>
21 1
#!C
22
struct gsm_subscriber *sub;
23
24
sub = db_get_subscriber(net, IMSI, imsi);
25
if (!subscr)
26
   return ERROR;
27
do_things_with_the_subsr(sub);
28 2
</pre>
29 1
30
needs to be changed into two methods and maybe needs extra error handling
31
32 2
<pre>
33 1
#!C
34
static void lu_subscr_cb(struct gsm_subscriber *subcr, void *data)
35
{
36
   struct gsm_subscriber_connection *conn = data;
37
   if (!subscr)
38
      return release_radio_channel(conn);
39
   do_things_with_the_subsr(sub);
40
}
41
42
...
43
db_get_subscriber(net, IMSI, imsi, lu_subscr_cb, conn);
44 2
</pre>
Add picture from clipboard (Maximum size: 48.8 MB)