/****************************************************************************
  module      : vkb05
  author      : JuergenA,UweH
  responsible : UweH
  special area: KB_functions
  see also    :
  description :
*****************************************************************************/
 
.tt 1 $SAP$LiveCache$VKB28$
.tt 3 $UweH$KB_shutdown$2000-07-21$
 
.nf
 
 
    ========== licence begin  GPL
    Copyright (C) 2000 SAP AG
 
    This program is free software; you can redistribute it and/or
    modify it under the terms of the GNU General Public License
    as published by the Free Software Foundation; either version 2
    of the License, or (at your option) any later version.
 
    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
    ========== licence end
 
.fo
***********************************************************
 
Module  : KB_shutdown
 
Define  :
 
        PROCEDURE
              k28emergency_shutdown (VAR t : tgg00_TransContext;
                    origin_mess_type       : tgg00_MessType);
 
        PROCEDURE
              k28shutdown (VAR t : tgg00_TransContext);
 
        PROCEDURE
              k28put_errtext (VAR t : tgg00_TransContext;
                    errtext : tsp00_ErrText);
 
.CM *-END-* define --------------------------------------
.sp;.cp 3
Use     :
 
        FROM
              KB_headmaster : VKB38;
 
        FUNCTION
              k38is_on_autosave (VAR t : tgg00_TransContext;
                    in_region : boolean) : boolean;
 
      ------------------------------ 
 
        FROM
              KB_Logging : VKB560;
 
        PROCEDURE
              kb560StartSavepointAndWait (VAR Trans : tgg00_TransContext;
                    MessType2 : tgg00_MessType2);
 
      ------------------------------ 
 
        FROM
              AK_Table : VAK11;
 
        PROCEDURE
              a11put_date_time (VAR date : tsp_int4;
                    VAR time : tsp_int4);
 
      ------------------------------ 
 
        FROM
              filesysteminterface_1 : VBD01;
 
        VAR
              b01downfilesystem : boolean;
 
      ------------------------------ 
 
        FROM
              error_text_handling : VBD06;
 
        PROCEDURE
              b06put_errtxt (VAR t : tgg00_TransContext;
                    pid           : tsp00_TaskId;
                    errlen        : integer;
                    etexttype     : tgg00_ErrorText;
                    b_err_in      : tgg00_BasisError;
                    VAR errtxt    : tsp00_ErrText;
                    VAR b_err_out : tgg00_BasisError);
 
      ------------------------------ 
 
        FROM
              Trace : VBD120;
 
        PROCEDURE
              b120InsertTrace (VAR t   : tgg00_TransContext;
                    trace_layer  : tgg00_Debug;
                    trace_object : tgg00_VtraceType;
                    body_len     : tsp00_Int2;
                    trace_body   : tgg11_VtraceBodyPtr);
 
      ------------------------------ 
 
        FROM
              Configuration_Parameter : VGG01;
 
        PROCEDURE
              g01abort (
                    msg_no     : tsp_int4;
                    msg_label  : tsp_c8;
                    msg_text   : tsp_c24;
                    bad_value  : tsp_int4);
 
        PROCEDURE
              g01optextmsg (msg_prio : tsp3_priority;
                    msg_type  : tsp3_msg_type;
                    msg_no    : tsp_int4;
                    msg_label : tsp_c8;
                    msg_text  : tsp_c40);
 
      ------------------------------ 
 
        FROM
              Kernel_move_and_fill : VGG10;
 
        PROCEDURE
              g10mv3 (mod_id   : tsp_c6;          mod_num    : tsp_int4;
                    source_upb : tsp_int4;        destin_upb : tsp_int4;
                    VAR source : tsp00_C40;       source_pos : tsp_int4;
                    VAR destin : tsp00_C40;       destin_pos : tsp_int4;
                    length     : tsp_int4;
                    VAR err    : tgg_basis_error);
 
      ------------------------------ 
 
        FROM
              GG_edit_routines : VGG17;
 
        PROCEDURE
              g17basis_err_to_line (b_err : tgg00_BasisError;
                    VAR ln_len : integer;
                    VAR ln     : tsp00_C40);
 
        PROCEDURE
              g17messtype_to_line (mess_type : tgg00_MessType;
                    VAR ln_len : integer;
                    VAR ln     : tsp00_C40);
 
      ------------------------------ 
 
        FROM
              RTE_kernel : VEN101;
 
        PROCEDURE
              vsleep (pid : tsp_process_id;
                    limit : tsp_int2);
 
.CM *-END-* use -----------------------------------------
.sp;.cp 3
Synonym :
 
        PROCEDURE
              b06put_errtxt;
 
              tsp00_C256 tsp00_ErrText
 
        PROCEDURE
              g10mv3;
 
              tsp_moveobj tsp00_C40
              tsp_moveobj tsp00_C40
 
        PROCEDURE
              g17basis_err_to_line;
 
              tsp00_Line tsp00_C40
 
        PROCEDURE
              g17messtype_to_line;
 
              tsp00_Line tsp00_C40
 
.CM *-END-* synonym -------------------------------------
.sp;.cp 3
Author  : JuergenA
.sp
.cp 3
Created : 1981-01-07
.sp
.cp 3
Version : 2002-08-01
.sp
.cp 3
Release :      Date : 2000-07-21
.sp
***********************************************************
.sp
.cp 11
.fo
.oc _/1
Specification:
.sp 2
Procedure K28EMERGENCY_SHUTDOWN
.sp
An immediate shutdown is carried out; a VTRACE entry is written
with the triggering command (ORIGIN_MESS_TYPE) and the error that has
occured (ORIGIN_ERROR).
.sp 2;.cp 3
Procedure K28ERRMSG
.sp
The procedure passes a message for the specified process
to the error text handler.
.sp 2;.cp 3
Procedure K28OP_MSG
.sp
Issues a console message with the DB name (location name).
.sp 2;.cp 4
Procedure K28REVOKE_SHUTDOWN
.sp
The shutdown request for a normal shutdown that could not be carried
out immediately is revoked.
.sp 2;.cp 5
Procedure K28SHUTDOWN
.sp
If no more write entries exist in the lock list, a checkpoint is
written that triggers the shutdown of the base layer.  If the lock
list still contains write locks, only the K28REQUEST_SHUTDOWN state
is set in the case of a normal shutdown whereas, for a quick shutdown,
a 'shutdown filesystem' occurs.
.CM *-END-* specification -------------------------------
.sp 2
***********************************************************
.sp
.cp 5
.fo
.oc _/1
Description:
 
.CM *-END-* description ---------------------------------
.sp 2
***********************************************************
.sp
.cp 5
.nf
.oc _/1
Structure:
 
.CM *-END-* structure -----------------------------------
.sp 2
**********************************************************
.sp
.cp 10
.nf
.oc _/1
.CM -lll-
Code    :
 
 
CONST
      c_in_region = true;
 
 
(*------------------------------*) 
 
PROCEDURE
      k28emergency_shutdown (VAR t : tgg00_TransContext;
            origin_mess_type       : tgg00_MessType);
      (******** hkb28.h ********)
 
CONST
      c_max_reschedule = 100;
 
VAR
      aux_err     : tgg00_BasisError;
      origin_err  : tgg00_BasisError;
      msg_len     : integer;
      err_len     : integer;
      type_len    : integer;
      count       : integer; (* PTS 1104449 JA 1999-11-03 *)
      shutd_trace : tgg11_KbDateTimeTrace;
      msg_txt     : tsp00_C40;
      err_txt     : tsp00_C40;
      type_txt    : tsp00_C40;
 
BEGIN
origin_err     := t.trError_gg00;
t.trError_gg00 := e_ok;
IF  NOT b01downfilesystem AND (origin_err = e_shutdown)
THEN
    (* PTS 1104449 JA 1999-11-03 *)
    BEGIN
    count := 1;
    WHILE NOT b01downfilesystem AND (count <= c_max_reschedule) DO
        BEGIN
        vsleep (t.trTaskId_gg00, 0); (* reschedule *)
        count := count + 1
        END
    (*ENDWHILE*) 
    END;
(*ENDIF*) 
IF  NOT b01downfilesystem
THEN
    BEGIN
    (* write vtrace entry *)
    shutd_trace.kbdtHead_gg11.kbMessType_gg11  := origin_mess_type;
    shutd_trace.kbdtHead_gg11.kbMessType2_gg11 := mm_nil;
    shutd_trace.kbdtHead_gg11.kbError_gg11     := origin_err;
    a11put_date_time (shutd_trace.kbdtDate_gg11, shutd_trace.kbdtTime_gg11);
    b120InsertTrace (t, kb, vttKbEmergencyShutdown_egg00, sizeof (shutd_trace), @shutd_trace);
    (* write detailed opmessage *)
    msg_txt  := bsp_c40;
    type_txt := bsp_c40;
    err_txt  := bsp_c40;
    msg_len  := 0;
    type_len := 0;
    err_len  := 0;
    g17messtype_to_line  (origin_mess_type, type_len, type_txt);
    g17basis_err_to_line (origin_err,       err_len,  err_txt );
    IF  type_len + err_len + 1 <= sizeof (tsp00_C40)
    THEN
        BEGIN
        aux_err := e_ok;
        g10mv3 ('VKB28 ',   1,    
              sizeof (type_txt), sizeof (msg_txt),
              type_txt, 1, msg_txt, msg_len + 1, type_len, aux_err);
        msg_len := msg_len + type_len;
        msg_txt [msg_len + 1] := '/';
        g10mv3 ('VKB28 ',   2,    
              sizeof (err_txt), sizeof (msg_txt),
              err_txt, 1, msg_txt, msg_len + 2, err_len, aux_err)
        END;
    (*ENDIF*) 
    g01optextmsg (sp3p_syscon, sp3m_error,
          kb28x1EmergencyShutd_csp03, csp3_n_shutdown, msg_txt)
    END;
(*ENDIF*) 
g01abort (kb28x1EmergencyShutd_csp03, csp3_n_shutdown,
      '*** EMERGENCY ***       ', ord (origin_err));
END;
 
(*------------------------------*) 
 
PROCEDURE
      k28shutdown (VAR t : tgg00_TransContext);
 
BEGIN
(* PTS 1114090 UH 2002-02-11 changed behaviour *)
t.trError_gg00 := e_ok;
IF  k38is_on_autosave (t, NOT c_in_region)
THEN
    t.trError_gg00 := e_autosave_running
ELSE
    BEGIN
    (* PTS 1119451 UH 2002-12-09 do not send cancel do not wait for anything *)
    t.trError_gg00 := e_ok;
    kb560StartSavepointAndWait (t, mm_down);
    (* it should not be possible to reach this code *)
    g01abort (kb28x1EmergencyShutd_csp03, csp3_n_shutdown,
          '*** SHUTDOWN FORCED *** ', ord (t.trError_gg00));
    END
(*ENDIF*) 
END;
 
(*------------------------------*) 
 
PROCEDURE
      k28put_errtext (VAR t : tgg00_TransContext;
            errtext : tsp00_ErrText);
 
VAR
      orig_err : tgg00_BasisError;
      aux_err  : tgg00_BasisError;
      len      : integer;
 
BEGIN
IF  errtext = bsp_c40
THEN
    len := 0
ELSE
    BEGIN
    len := sizeof (errtext);
    WHILE (len > 1) AND (errtext [len] = ' ') DO
        len := len - 1;
    (*ENDWHILE*) 
    orig_err := t.trError_gg00;
    b06put_errtxt (t, t.trTaskId_gg00, len, errtext_char,
          orig_err, errtext, aux_err);
    IF  (t.trError_gg00 = e_ok)
        AND NOT (tsErrTextExist_egg00 in t.trState_gg00)
    THEN
        t.trState_gg00 := t.trState_gg00 + [tsErrTextExist_egg00];
    (*ENDIF*) 
    t.trError_gg00 := orig_err
    END
(*ENDIF*) 
END;
 
.CM *-END-* code ----------------------------------------
.SP 2 
***********************************************************
*-PRETTY-*  statements    :         49
*-PRETTY-*  lines of code :        143        PRETTYX 3.10 
*-PRETTY-*  lines in file :        437         1997-12-10 
.PA 
