Annotation of 42BSD/ingres/source/dbu/update.c, revision 1.1.1.1

1.1       root        1: # include      <ingres.h>
                      2: # include      <resp.h>
                      3: # include      <aux.h>
                      4: # include      <symbol.h>
                      5: # include      <access.h>
                      6: # include      <batch.h>
                      7: # include      <sccs.h>
                      8: 
                      9: SCCSID(@(#)update.c    7.1     2/5/81)
                     10: 
                     11: /*
                     12: **     Update reads a batch file written by the
                     13: **     access method routines (openbatch, addbatch, closebatch)
                     14: **     and performs the updates stored in the file.
                     15: **
                     16: **     It assumes that it is running in the database. It
                     17: **     is driven by the data in the Batchhd struct (see ../batch.h).
                     18: **     If the relation has a secondary index then update calls
                     19: **     secupdate. As a last step the batch file is removed.
                     20: **
                     21: **     The global flag Batch_recovery is tested in case
                     22: **     of an error. It should be FALSE if update is being
                     23: **     run as the dbu deferred update processor. It should
                     24: **     be TRUE if it is being used as part of the recovery
                     25: **     procedure.
                     26: */
                     27: 
                     28: update()
                     29: {
                     30:        register int    i, mode;
                     31:        DESC            rel;
                     32:        long            oldtid, tupcnt;
                     33:        char            oldtup[MAXTUP], newtup[MAXTUP];
                     34:        char            *batchname();
                     35: 
                     36: #      ifdef xZTR1
                     37:        if (tTf(48, -1))
                     38:                printf("Update on %s\n", batchname());
                     39: #      endif
                     40:        /* set up to read batchhd */
                     41:        Batch_cnt = BATCHSIZE;  /* force a read on next getbatch */
                     42:        Batch_dirty = FALSE;
                     43:        if ((Batch_fp = open(batchname(), 2)) < 0)
                     44:                syserr("prim:can't open %s", batchname());
                     45:        getbatch(&Batchhd, sizeof Batchhd);
                     46: 
                     47:        tupcnt = Batchhd.num_updts;
                     48: #      ifdef xZTR1
                     49:        if (tTf(48, 0))
                     50:                printf("rel=%s tups=%ld\n", Batchhd.rel_name, tupcnt);
                     51: #      endif
                     52:        Resp.resp_tups = 0;
                     53:        if (!tupcnt)
                     54:        {
                     55:                rmbatch();
                     56:                return (1);
                     57:        }
                     58: 
                     59:        /* update the primary relation */
                     60:        if (i = openr(&rel, 2, Batchhd.rel_name))
                     61:                syserr("prim:can't openr %s %d", Batchhd.rel_name, i);
                     62:        mode = Batchhd.mode_up;
                     63: 
                     64:        while (tupcnt--)
                     65:        {
                     66:                getbatch(&oldtid, Batchhd.tido_size);   /* read old tid */
                     67:                getbatch(oldtup, Batchhd.tupo_size);    /* and portions of old tuple */
                     68:                getbatch(newtup, Batchhd.tupn_size);    /* and the newtup */
                     69: 
                     70:                switch (mode)
                     71:                {
                     72: 
                     73:                  case mdDEL:
                     74:                        if ((i = delete(&rel, &oldtid)) < 0)
                     75:                                syserr("prim:bad del %d %s", i, Batchhd.rel_name);
                     76:                        break;
                     77: 
                     78:                  case mdREPL:
                     79:                        if (i = replace(&rel, &oldtid, newtup, TRUE))
                     80:                        {
                     81:                                /* if newtuple is a duplicate, then ok */
                     82:                                if (i == 1)
                     83:                                        break;
                     84:                                /* if this is recovery and oldtup not there, try to insert newtup */
                     85:                                if (Batch_recovery && i == 2)
                     86:                                        goto upinsert;
                     87:                                syserr("prim:Non-functional replace on %s (%d)", i, Batchhd.rel_name);
                     88:                        }
                     89:                        Resp.resp_tups++;
                     90:                        break;
                     91: 
                     92:                  case mdAPP:
                     93:                  upinsert:
                     94:                        if ((i = insert(&rel, &oldtid, newtup, TRUE)) < 0)
                     95:                                syserr("prim:bad insert %d %s", i, Batchhd.rel_name);
                     96:                        break;
                     97: 
                     98:                  default:
                     99:                        syserr("prim:impossible mode %d", mode);
                    100:                }
                    101:                putbatch(&oldtid, Batchhd.tidn_size);   /* write new tid if necessary */
                    102:        }
                    103:        /* fix the tupchanged count if delete or append */
                    104:        if (mode != mdREPL)
                    105:                Resp.resp_tups = rel.reladds >= 0 ? rel.reladds : -rel.reladds;
                    106:        /* close the relation but secupdate will still use the decriptor */
                    107:        if (i = closer(&rel))
                    108:                syserr("prim:close err %d %s", i, Batchhd.rel_name);
                    109:        batchflush();
                    110: 
                    111:        /* if this relation is indexed, update the indexes */
                    112:        if (rel.reldum.relindxd > 0)
                    113:                secupdate(&rel);
                    114:        rmbatch();
                    115: 
                    116: #      ifdef xZTR1
                    117:        if (tTf(48, 2))
                    118:                printf("%ld tups changed\n", Resp.resp_tups);
                    119: #      endif
                    120:        return (0);
                    121: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.