SQLite

Check-in [2f2a8a69cb]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Account for a malloc failure in the asynchronous writer thread in test_async.c (CVS 3096)
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 2f2a8a69cb380dc30b85a792c369020fec3c79a5
User & Date: danielk1977 2006-02-14 14:02:08.000
Context
2006-02-14
14:46
test_async.c: Writer-thread should not relinquish mutex when writing a file for which only one file handle is open (fixes bug introduced in (3093)). (CVS 3097) (check-in: f0c45b7eab user: danielk1977 tags: trunk)
14:02
Account for a malloc failure in the asynchronous writer thread in test_async.c (CVS 3096) (check-in: 2f2a8a69cb user: danielk1977 tags: trunk)
13:48
Fix bug in test_async.c version of OsFileSize(). (CVS 3095) (check-in: 239e53b4f2 user: danielk1977 tags: trunk)
Changes
Unified Diff Ignore Whitespace Patch
Changes to src/test_async.c.
1072
1073
1074
1075
1076
1077
1078

1079
1080
1081
1082
1083
1084
1085
      async.ioError = rc;
    }

    /* Drop the queue mutex before continuing to the next write operation
    ** in order to give other threads a chance to work with the write queue.
    */
    if( !async.pQueueFirst || !async.ioError ){

      pthread_mutex_unlock(&async.queueMutex);
      holdingMutex = 0;
      if( async.ioDelay>0 ){
        sqlite3OsSleep(async.ioDelay);
      }else{
        sched_yield();
      }







>







1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
      async.ioError = rc;
    }

    /* Drop the queue mutex before continuing to the next write operation
    ** in order to give other threads a chance to work with the write queue.
    */
    if( !async.pQueueFirst || !async.ioError ){
      sqlite3ApiExit(0, 0);
      pthread_mutex_unlock(&async.queueMutex);
      holdingMutex = 0;
      if( async.ioDelay>0 ){
        sqlite3OsSleep(async.ioDelay);
      }else{
        sched_yield();
      }
Changes to test/async2.test.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#
#    May you do good and not evil.
#    May you find forgiveness for yourself and forgive others.
#    May you share freely, never taking more than you give.
#
#***********************************************************************
#
# $Id: async2.test,v 1.2 2006/02/14 13:48:34 danielk1977 Exp $


if {[info commands sqlite3async_enable]==""} {
  # The async logic is not built into this system
  return
}








|







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#
#    May you do good and not evil.
#    May you find forgiveness for yourself and forgive others.
#    May you share freely, never taking more than you give.
#
#***********************************************************************
#
# $Id: async2.test,v 1.3 2006/02/14 14:02:08 danielk1977 Exp $


if {[info commands sqlite3async_enable]==""} {
  # The async logic is not built into this system
  return
}

37
38
39
40
41
42
43


44
45
46

47
48
49
50
51
52
53
54
55
56

57


58
59
60
61
62


63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102

103
104
105
106
107
108
109
110
  COMMIT;

  UPDATE counter SET c = 'FIN';
}

db close



set ::go 1
for {set n 3} {$::go} {incr n} {
  set ::sqlite_io_error_pending 0

  file delete -force test.db test.db-journal
  sqlite3 db test.db
  execsql $::setup_script
  db close

  sqlite3async_enable 1
  sqlite3 db test.db
  execsql $::sql_script
  db close


  set ::sqlite_io_error_pending $n


  sqlite3async_halt idle
  sqlite3async_start
  sqlite3async_wait

  set ::sqlite_io_error_pending 0


  sqlite3 db test.db
  set c [db eval {SELECT c FROM counter LIMIT 1}]
  switch -- $c {
    1 {
      do_test async-ioerr-1.1.$n {
        execsql {
          SELECT name FROM sqlite_master;
        }
      } {counter}
    }
    2 {
      do_test async-ioerr-1.2.$n.1 {
        execsql {
          SELECT * FROM t1;
        }
      } {}
      do_test async-ioerr-1.2.$n.2 {
        execsql {
          SELECT * FROM t2;
        }
      } {}
    }
    3 {
      do_test async-ioerr-1.3.$n.1 {
        execsql {
          SELECT * FROM t1;
        }
      } {abcdefghij four score}
      do_test async-ioerr-1.3.$n.2 {
        execsql {
          SELECT * FROM t2;
        }
      } {klmnopqrst and seven}
    }
    FIN {
      set ::go 0
    }
  }

  sqlite3async_enable 0

}

catch {db close}
sqlite3async_halt idle
sqlite3async_start
sqlite3async_wait

finish_test







>
>
|
|
|
>
|
|
|
|
|
|
|
|
|
|
>
|
>
>
|
|
|
|
|
>
>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
>








37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
  COMMIT;

  UPDATE counter SET c = 'FIN';
}

db close


foreach err [list ioerr malloc] {
  set ::go 1
  for {set n 1} {$::go} {incr n} {
    set ::sqlite_io_error_pending 0
    sqlite_malloc_fail 0
    file delete -force test.db test.db-journal
    sqlite3 db test.db
    execsql $::setup_script
    db close
  
    sqlite3async_enable 1
    sqlite3 db test.db
    execsql $::sql_script
    db close
  
    switch -- $err {
      ioerr  { set ::sqlite_io_error_pending $n }
      malloc { sqlite_malloc_fail $n }
    }
    sqlite3async_halt idle
    sqlite3async_start
    sqlite3async_wait
  
    set ::sqlite_io_error_pending 0
    sqlite_malloc_fail 0

    sqlite3 db test.db
    set c [db eval {SELECT c FROM counter LIMIT 1}]
    switch -- $c {
      1 {
        do_test async-$err-1.1.$n {
          execsql {
            SELECT name FROM sqlite_master;
          }
        } {counter}
      }
      2 {
        do_test async-$err-1.2.$n.1 {
          execsql {
            SELECT * FROM t1;
          }
        } {}
        do_test async-$err-1.2.$n.2 {
          execsql {
            SELECT * FROM t2;
          }
        } {}
      }
      3 {
        do_test async-$err-1.3.$n.1 {
          execsql {
            SELECT * FROM t1;
          }
        } {abcdefghij four score}
        do_test async-$err-1.3.$n.2 {
          execsql {
            SELECT * FROM t2;
          }
        } {klmnopqrst and seven}
      }
      FIN {
        set ::go 0
      }
    }
  
    sqlite3async_enable 0
  }
}

catch {db close}
sqlite3async_halt idle
sqlite3async_start
sqlite3async_wait

finish_test