[PATCH] osmo-msc[master]: Delete SMS from the database once they were sent successfully

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

Stefan Sperling gerrit-no-reply at lists.osmocom.org
Thu Jan 18 17:58:57 UTC 2018


Review at  https://gerrit.osmocom.org/5882

Delete SMS from the database once they were sent successfully

Currently the SMS database keeps accumulating entries for each SMS.
These entries are never deleted automatically. With this change, we
start deleting SMS which have successfully been sent to subscriber B.

Change-Id: I3749855fe25d9d4e37ec96b0c2bffbc692b66a78
---
M include/osmocom/msc/db.h
M src/libmsc/db.c
M src/libmsc/sms_queue.c
3 files changed, 18 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/osmo-msc refs/changes/82/5882/1

diff --git a/include/osmocom/msc/db.h b/include/osmocom/msc/db.h
index 988c9bd..13c5ed3 100644
--- a/include/osmocom/msc/db.h
+++ b/include/osmocom/msc/db.h
@@ -49,6 +49,7 @@
 int db_sms_mark_delivered(struct gsm_sms *sms);
 int db_sms_inc_deliver_attempts(struct gsm_sms *sms);
 int db_sms_delete_by_msisdn(const char *msisdn);
+int db_sms_delete_sent_message_by_id(unsigned long long sms_id);
 
 /* Statistics counter storage */
 struct osmo_counter;
diff --git a/src/libmsc/db.c b/src/libmsc/db.c
index 7007c7a..e80ef53 100644
--- a/src/libmsc/db.c
+++ b/src/libmsc/db.c
@@ -970,6 +970,22 @@
 	return 0;
 }
 
+int db_sms_delete_sent_message_by_id(unsigned long long sms_id)
+{
+	dbi_result result;
+
+	result = dbi_conn_queryf(conn,
+			"DELETE FROM SMS WHERE id = %llu AND sent is NOT NULL",
+			 sms_id);
+	if (!result) {
+		LOGP(DDB, LOGL_ERROR, "Failed to delete SMS %llu.\n", sms_id);
+		return 1;
+	}
+
+	dbi_result_free(result);
+	return 0;
+}
+
 int db_store_counter(struct osmo_counter *ctr)
 {
 	dbi_result result;
diff --git a/src/libmsc/sms_queue.c b/src/libmsc/sms_queue.c
index 609a0db..1372a2c 100644
--- a/src/libmsc/sms_queue.c
+++ b/src/libmsc/sms_queue.c
@@ -483,6 +483,7 @@
 		network->sms_queue->pending -= 1;
 		vsub = vlr_subscr_get(pending->vsub);
 		sms_pending_free(pending);
+		db_sms_delete_sent_message_by_id(pending->sms_id);
 		/* Attempt to send another SMS to this subscriber */
 		sms_send_next(vsub);
 		vlr_subscr_put(vsub);

-- 
To view, visit https://gerrit.osmocom.org/5882
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I3749855fe25d9d4e37ec96b0c2bffbc692b66a78
Gerrit-PatchSet: 1
Gerrit-Project: osmo-msc
Gerrit-Branch: master
Gerrit-Owner: Stefan Sperling <ssperling at sysmocom.de>



More information about the gerrit-log mailing list