Record news more compactly

Member nws_uid is unused since the commit before previous.  Remove it.

Member nws_seqno is of marginal value, because we write news only
through ncache[], and thus aren't prone to the errors sequence numbers
can catch.  Remove it.

Make timestamp selector virtual, computing nws_when + nws_duration,
and remove member nws_timestamp.  Impact:

* In ncache(), the removed timestamp equals nws_when + nws_duration,
  both for new news and updated news.  No change.

* delete_old_news() becomes invisible.  Before, its move of unexpired
  news to the beginning of the news file touched all the timestamps.
  That was unwanted, because the move does not change news, only their
  storage.  Improvement.

* empdump no longer flags the imported news changed via the timestamp.
  This is somewhat unfortunate.  Document as bug.

With these members removed, struct nwsstr no longer matches struct
emptypedstr, so clear news table flag EFF_TYPED and remove union
empobj_storage member news.  This loses the automatic maintenance of
member ef_type via struct emptypedstr.  Remove ef_type as well.

This shrinks struct nwsstr from 20 to 12 bytes on common 32 bit
machines, and from 32 to 16 bytes on common 64 bit machines.  Since
the server doesn't map the whole news file (EFF_MAP is off), this
reduces I/O, while the table's memory use remains the same.

Historical note: struct nwsstr is now pretty much what it was back in
BSD Empire 1.1.  Members ef_type and nws_uid go back to Empire 3 (for
C_SYNC?).  v4.3.12 added member nws_timestamp, which doubled the size
on common 64 bit machines.  v4.3.15 added nws_seqno.
This commit is contained in:
Markus Armbruster 2009-12-31 09:18:37 +01:00
parent b719f39c0f
commit 0ba61f1714
6 changed files with 14 additions and 12 deletions

View file

@ -84,7 +84,6 @@ union empobj_storage {
struct lonstr loan; struct lonstr loan;
struct loststr lost; struct loststr lost;
struct natstr nat; struct natstr nat;
struct nwsstr news;
struct nukstr nuke; struct nukstr nuke;
struct plnstr plane; struct plnstr plane;
struct realmstr realm; struct realmstr realm;

View file

@ -45,12 +45,6 @@
#include "nsc.h" #include "nsc.h"
struct nwsstr { struct nwsstr {
/* initial part must match struct empobj */
short ef_type;
short nws_uid;
unsigned nws_seqno;
time_t nws_timestamp;
/* end of part matching struct empobj */
natid nws_ano; /* "actor" country # */ natid nws_ano; /* "actor" country # */
unsigned char nws_vrb; /* action (verb) */ unsigned char nws_vrb; /* action (verb) */
natid nws_vno; /* "victim" country # */ natid nws_vno; /* "victim" country # */

View file

@ -97,6 +97,8 @@ yet available in human-readable form: the lost file, sect-chr selector
nav, ship and land plague status (deity only), plane theta (governs nav, ship and land plague status (deity only), plane theta (governs
satellite movement), trade selectors xloc, yloc, commodity selectors satellite movement), trade selectors xloc, yloc, commodity selectors
xbuy, ybuy. xbuy, ybuy.
Incremental dump doesn't work after importing news with the empdump
utility.
.s1 .s1
.L "FUTURE DIRECTIONS:" .L "FUTURE DIRECTIONS:"
xdump is still fairly new, and experience with it may lead to changes. xdump is still fairly new, and experience with it may lead to changes.

View file

@ -133,7 +133,7 @@ struct empfile empfile[] = {
{EF_NUKE, "nuke", "nuke", nuke_ca, {EF_NUKE, "nuke", "nuke", nuke_ca,
UNMAPPED_CACHE(struct nukstr, EFF_TYPED | EFF_XY | EFF_OWNER)}, UNMAPPED_CACHE(struct nukstr, EFF_TYPED | EFF_XY | EFF_OWNER)},
{EF_NEWS, "news", "news", news_ca, {EF_NEWS, "news", "news", news_ca,
UNMAPPED_CACHE(struct nwsstr, EFF_TYPED)}, UNMAPPED_CACHE(struct nwsstr, 0)},
{EF_TREATY, "treaty", "treaty", treaty_ca, {EF_TREATY, "treaty", "treaty", treaty_ca,
UNMAPPED_CACHE(struct trtstr, EFF_TYPED)}, UNMAPPED_CACHE(struct trtstr, EFF_TYPED)},
{EF_TRADE, "trade", "trade", trade_ca, {EF_TRADE, "trade", "trade", trade_ca,

View file

@ -67,6 +67,7 @@ static void *nsc_lnd_acc(struct valstr *, struct natstr *, void *);
static void *nsc_lnd_dam(struct valstr *, struct natstr *, void *); static void *nsc_lnd_dam(struct valstr *, struct natstr *, void *);
static void *nsc_lnd_aaf(struct valstr *, struct natstr *, void *); static void *nsc_lnd_aaf(struct valstr *, struct natstr *, void *);
static void *nsc_lchr(struct valstr *, struct natstr *, void *); static void *nsc_lchr(struct valstr *, struct natstr *, void *);
static void *nsc_nws_timestamp(struct valstr *, struct natstr *, void *);
/* Ugly hack to improve legibility by avoid long lines */ /* Ugly hack to improve legibility by avoid long lines */
#define fldoff(fld) offsetof(CURSTR, fld) #define fldoff(fld) offsetof(CURSTR, fld)
@ -468,9 +469,7 @@ struct castr loan_ca[] = {
struct castr news_ca[] = { struct castr news_ca[] = {
#define CURSTR struct nwsstr #define CURSTR struct nwsstr
/* no need for uid as long as it's not referenced from other tables */ {"timestamp", 0, NSC_LONG, 0, nsc_nws_timestamp, EF_BAD, NSC_EXTRA},
{"timestamp", fldoff(nws_timestamp), NSC_TIME, 0, NULL,
EF_BAD, NSC_EXTRA},
{"actor", fldoff(nws_ano), NSC_NATID, 0, NULL, EF_NATION, 0}, {"actor", fldoff(nws_ano), NSC_NATID, 0, NULL, EF_NATION, 0},
{"action", fldoff(nws_vrb), NSC_UCHAR, 0, NULL, EF_NEWS_CHR, 0}, {"action", fldoff(nws_vrb), NSC_UCHAR, 0, NULL, EF_NEWS_CHR, 0},
{"victim", fldoff(nws_vno), NSC_NATID, 0, NULL, EF_NATION, 0}, {"victim", fldoff(nws_vno), NSC_NATID, 0, NULL, EF_NATION, 0},
@ -915,3 +914,12 @@ nsc_lchr(struct valstr *val, struct natstr *np, void *ptr)
val->val_as.sym.get = NULL; val->val_as.sym.get = NULL;
return lchr + ((struct lndstr *)ptr)->lnd_type; return lchr + ((struct lndstr *)ptr)->lnd_type;
} }
static void *
nsc_nws_timestamp(struct valstr *val, struct natstr *natp, void *ptr)
{
struct nwsstr *np = ptr;
val->val_as.lng = np->nws_when + np->nws_duration;
return NULL;
}

View file

@ -117,7 +117,6 @@ delete_old_news(void)
for (j = 0; getnews(i + j, &news); j++) { for (j = 0; getnews(i + j, &news); j++) {
if (news.nws_vrb == 0) if (news.nws_vrb == 0)
break; break;
ef_set_uid(EF_NEWS, &news, j);
putnews(j, &news); putnews(j, &news);
} }
CANT_HAPPEN(i + j != news_tail); CANT_HAPPEN(i + j != news_tail);