Merge lp:~zorba-coders/zorba/plan-serializer into lp:zorba

Proposed by Daniel Turcanu
Status: Superseded
Proposed branch: lp:~zorba-coders/zorba/plan-serializer
Merge into: lp:zorba
Diff against target: 405 lines (+110/-21)
14 files modified
src/api/xqueryimpl.cpp (+2/-1)
src/compiler/api/compilercb.cpp (+17/-0)
src/compiler/api/compilercb.h (+5/-2)
src/compiler/expression/var_expr.cpp (+1/-0)
src/compiler/translator/translator.cpp (+5/-3)
src/context/static_context.cpp (+1/-0)
src/context/static_context.h (+2/-0)
src/functions/udf.cpp (+24/-5)
src/functions/udf.h (+6/-1)
src/zorbaserialization/archiver.cpp (+4/-1)
src/zorbaserialization/archiver.h (+1/-1)
src/zorbaserialization/zorba_class_serializer.h (+3/-5)
src/zorbatypes/rchandle.h (+2/-2)
src/zorbatypes/rclist.h (+37/-0)
To merge this branch: bzr merge lp:~zorba-coders/zorba/plan-serializer
Reviewer Review Type Date Requested Status
Markos Zaharioudakis Pending
Chris Hillery Pending
Zorba Coders Pending
Review via email: mp+88783@code.launchpad.net

This proposal has been superseded by a proposal from 2012-01-18.

Commit message

Fix in plan serializer about preparing user_functions plan for serialization.

Description of the change

Fix in plan serializer about preparing user_functions plan for serialization.

To post a comment you must log in.
Revision history for this message
Markos Zaharioudakis (markos-za) wrote :

I would like to understand this better. What is the problem that this change fixes?

Revision history for this message
Daniel Turcanu (danielturcanu) wrote :

The user_functions were compiled during plan serialization, and this modified some expr trees that were already serialized. I had to ensure that all user_functions are compiled before plan serialization is started.

Revision history for this message
Markos Zaharioudakis (markos-za) wrote :

> The user_functions were compiled during plan serialization, and this modified
> some expr trees that were already serialized. I had to ensure that all
> user_functions are compiled before plan serialization is started.

Yes, I understood that myself, but what exactly was modified after having been serialized?

Revision history for this message
Daniel Turcanu (danielturcanu) wrote :

For example in one test, in flwor_expr object, theClauses was receiving another flwor_clause in the vector, which made the vector to increase and move to another space. But the initial flwor_clause had already been serialized, and its address was registered for address duplication detection. Sometimes another object would be allocated at the same address, and the plan serializer thought it is the same object. This only occured sometimes, so the problem was hard to debug.
So as a rule, all the objects should freeze during plan serialization, nothing should change.

Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :

The attempt to merge lp:~danielturcanu/zorba/plan-serializer into lp:zorba failed. Below is the output from the failed tests.

CMake Error at /home/ceej/zo/testing/zorbatest/tester/TarmacLander.cmake:273 (message):
  Validation queue job plan-serializer-2012-01-18T10-22-58.412Z is finished.
  The final status was:

  No tests were run - build or configure step must have failed.

  Not commiting changes.

Error in read script: /home/ceej/zo/testing/zorbatest/tester/TarmacLander.cmake

Revision history for this message
Chris Hillery (ceejatec) wrote :

Code does not compile. I would fix if this branch was owned by ~zorba-coders, but since it's ~danielturcanu, we'll need Daniel to fix it.

[ 13%] Building CXX object src/CMakeFiles/zorba_simplestore.dir/api/xqueryimpl.cpp.o
.In file included from ../../src/api/xqueryimpl.cpp:58:
../../src/compiler/api/compilercb.h:169: warning: '>>' operator will be treated as two right angle brackets in C++0x
../../src/compiler/api/compilercb.h:169: warning: suggest parentheses around '>>' expression
../../src/compiler/api/compilercb.h:169: error: 'theLocalUdfs' was not declared in this scope
../../src/compiler/api/compilercb.h:169: error: '>>' should be '> >' within a nested template argument list
../../src/compiler/api/compilercb.h:176: warning: '>>' operator will be treated as two right angle brackets in C++0x
../../src/compiler/api/compilercb.h:176: warning: suggest parentheses around '>>' expression
../../src/compiler/api/compilercb.h:176: error: a function call cannot appear in a constant-expression
../../src/compiler/api/compilercb.h:176: error: '>>' should be '> >' within a nested template argument list

10531. By Daniel Turcanu

Fix linux build

Revision history for this message
Markos Zaharioudakis (markos-za) wrote :

> For example in one test, in flwor_expr object, theClauses was receiving
> another flwor_clause in the vector, which made the vector to increase and move
> to another space. But the initial flwor_clause had already been serialized,
> and its address was registered for address duplication detection. Sometimes
> another object would be allocated at the same address, and the plan serializer
> thought it is the same object. This only occured sometimes, so the problem was
> hard to debug.
> So as a rule, all the objects should freeze during plan serialization, nothing
> should change.

I am sorry, but this still does not answer my question. I assume that the flwor_expr is inside the body of a udf. Are you saying that this body is somehow serialized, without having being optimized yet? If yes, I don't understand how this is possible, given that user_function::serialize() will first optimize the body (if not optimized already) before serializing it. Either I am missing something, or the real bug is somewhere else and you are just covering it up with this patch.

Revision history for this message
Daniel Turcanu (danielturcanu) wrote :

In my debugging I saw that the flwor_expr is outside the udf. So when compiling a udf, probably the optimizer is changing the expression tree in other places as well, probably the caller of the udf, but I cannot say for sure. This woulnd't surprise me, it should be normal for an optimizer.

10532. By Daniel Turcanu

Update to trunk

10533. By Daniel Turcanu

Fix Win build

10534. By Daniel Turcanu

Update to trunk

10535. By Daniel Turcanu

Update to trunk

10536. By Daniel Turcanu

Fix plan serializer for some full text classes

10537. By Matthias Brantner

fix for bug #924205

10538. By Daniel Turcanu

Update to trunk

Unmerged revisions

10538. By Daniel Turcanu

Update to trunk

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/api/xqueryimpl.cpp'
2--- src/api/xqueryimpl.cpp 2012-01-11 17:30:25 +0000
3+++ src/api/xqueryimpl.cpp 2012-01-18 11:01:27 +0000
4@@ -193,7 +193,8 @@
5 }
6 else
7 {
8- ar.compiler_cb = theCompilerCB;
9+ //ar.compiler_cb = theCompilerCB;
10+ theCompilerCB->prepare_for_serialize();
11 }
12
13 ar & theCompilerCB;
14
15=== modified file 'src/compiler/api/compilercb.cpp'
16--- src/compiler/api/compilercb.cpp 2012-01-11 17:30:25 +0000
17+++ src/compiler/api/compilercb.cpp 2012-01-18 11:01:27 +0000
18@@ -27,6 +27,7 @@
19 #include "system/properties.h"
20
21 #include "zorbaserialization/serialization_engine.h"
22+#include "functions/udf.h"
23
24
25 namespace zorba
26@@ -120,6 +121,7 @@
27 theTimeout(timeout),
28 theTempIndexCounter(0)
29 {
30+ theLocalUdfs = new rclist<user_function*>;
31 }
32
33
34@@ -143,6 +145,7 @@
35 theTempIndexCounter(0),
36 theConfig(cb.theConfig)
37 {
38+ theLocalUdfs = new rclist<user_function*>;
39 }
40
41
42@@ -169,6 +172,20 @@
43 {
44 }
45
46+//compile all the user_functions so the expr tree is stable at serialize
47+void CompilerCB::prepare_for_serialize()
48+{
49+ rclist<user_function*>::iterator udf_it;
50+ for(udf_it=theLocalUdfs->begin(); udf_it != theLocalUdfs->end(); udf_it++)
51+ {
52+ (*udf_it)->prepare_for_serialize(this);
53+ }
54+}
55+
56+rchandle<rclist<user_function*> > CompilerCB::get_local_udfs()
57+{
58+ return theLocalUdfs;
59+}
60
61 /*******************************************************************************
62
63
64=== modified file 'src/compiler/api/compilercb.h'
65--- src/compiler/api/compilercb.h 2012-01-11 17:30:25 +0000
66+++ src/compiler/api/compilercb.h 2012-01-18 11:01:27 +0000
67@@ -29,7 +29,7 @@
68 // without having the definition of static_context availble.
69 # include "context/static_context.h"
70 #endif
71-
72+#include "zorbatypes/rclist.h"
73 #include "zorbaserialization/class_serializer.h"
74
75 namespace zorba {
76@@ -39,7 +39,6 @@
77 #endif
78 class static_context;
79
80-
81 /*******************************************************************************
82 There is one CompilerCB per query plus one CompilerCB per invocation of an
83 eval or xqdoc expression that appears in the query. The query-level ccb is
84@@ -167,10 +166,14 @@
85
86 config theConfig;
87
88+ rchandle<rclist<user_function*> > theLocalUdfs;//for plan serializer
89+
90 public:
91 SERIALIZABLE_CLASS(CompilerCB);
92 CompilerCB(::zorba::serialization::Archiver& ar);
93 void serialize(::zorba::serialization::Archiver& ar);
94+ void prepare_for_serialize();
95+ rchandle<rclist<user_function*> > get_local_udfs();
96
97 public:
98 CompilerCB(XQueryDiagnostics*, long timeout = -1);
99
100=== modified file 'src/compiler/expression/var_expr.cpp'
101--- src/compiler/expression/var_expr.cpp 2012-01-11 17:30:25 +0000
102+++ src/compiler/expression/var_expr.cpp 2012-01-18 11:01:27 +0000
103@@ -134,6 +134,7 @@
104 ar & theCopyClause;
105 ar & theParamPos;
106 ar & theUDF;
107+ ar & theSetExprs;
108 ar & theIsPrivate;
109 ar & theIsExternal;
110 ar & theIsMutable;
111
112=== modified file 'src/compiler/translator/translator.cpp'
113--- src/compiler/translator/translator.cpp 2012-01-11 17:30:25 +0000
114+++ src/compiler/translator/translator.cpp 2012-01-18 11:01:27 +0000
115@@ -3331,7 +3331,7 @@
116 }
117 else // Process UDF (non-external) function declaration
118 {
119- f = new user_function(loc, sig, NULL, scriptKind); // no body for now
120+ f = new user_function(loc, sig, NULL, scriptKind, theCCB); // no body for now
121 }
122
123 f->setAnnotations(theAnnotations);
124@@ -10424,7 +10424,8 @@
125 user_function* udf = new user_function(loc,
126 fn->getSignature(),
127 NULL, // no body for now
128- fn->getScriptingKind());
129+ fn->getScriptingKind(),
130+ theCCB);
131
132 std::vector<expr_t> foArgs(arity);
133 std::vector<var_expr_t> udfArgs(arity);
134@@ -10632,7 +10633,8 @@
135 user_function_t udf(new user_function(loc,
136 signature(0, paramTypes, returnType),
137 body.getp(),
138- body->get_scripting_detail()));
139+ body->get_scripting_detail(),
140+ theCCB));
141 udf->setArgVars(argVars);
142 udf->setOptimized(true);
143
144
145=== modified file 'src/context/static_context.cpp'
146--- src/context/static_context.cpp 2012-01-11 17:30:25 +0000
147+++ src/context/static_context.cpp 2012-01-18 11:01:27 +0000
148@@ -22,6 +22,7 @@
149 #include <zorba/external_module.h>
150 #include <zorba/serialization_callback.h>
151
152+#include "functions/udf.h"
153 #include "zorbaserialization/serialization_engine.h"
154
155 #include "zorbamisc/ns_consts.h"
156
157=== modified file 'src/context/static_context.h'
158--- src/context/static_context.h 2012-01-11 17:30:25 +0000
159+++ src/context/static_context.h 2012-01-18 11:01:27 +0000
160@@ -599,6 +599,8 @@
161
162 void serialize(serialization::Archiver& ar);
163
164+ void prepare_for_serialize(CompilerCB *compiler_cb);
165+
166 public:
167 static_context(::zorba::serialization::Archiver& ar);
168
169
170=== modified file 'src/functions/udf.cpp'
171--- src/functions/udf.cpp 2012-01-14 21:58:23 +0000
172+++ src/functions/udf.cpp 2012-01-18 11:01:27 +0000
173@@ -50,7 +50,8 @@
174 const QueryLoc& loc,
175 const signature& sig,
176 expr_t expr_body,
177- short scriptingKind)
178+ short scriptingKind,
179+ CompilerCB *compilerCB)
180 :
181 function(sig, FunctionConsts::FN_UNKNOWN),
182 theLoc(loc),
183@@ -68,6 +69,8 @@
184 resetFlag(FunctionConsts::isBuiltin);
185 setDeterministic(true);
186 setPrivate(false);
187+ theLocalUdfs = compilerCB->get_local_udfs();
188+ theLocalUdfs->push_back(this);
189 }
190
191
192@@ -88,8 +91,22 @@
193 ********************************************************************************/
194 user_function::~user_function()
195 {
196-}
197-
198+ if(theLocalUdfs != NULL)
199+ theLocalUdfs->remove(this);
200+}
201+
202+
203+void user_function::prepare_for_serialize(CompilerCB *compilerCB)
204+{
205+ uint32_t planStateSize;
206+ getPlan(compilerCB, planStateSize);
207+ std::vector<user_function*>::iterator udf_it;
208+ for(udf_it=theMutuallyRecursiveUDFs.begin(); udf_it!=theMutuallyRecursiveUDFs.end();udf_it++)
209+ {
210+ if((*udf_it)->thePlan == NULL)
211+ (*udf_it)->prepare_for_serialize(compilerCB);
212+ }
213+}
214
215 /*******************************************************************************
216
217@@ -124,8 +141,10 @@
218 getPlan(ar.compiler_cb);
219 }
220 #else
221- uint32_t planStateSize;
222- getPlan(ar.compiler_cb, planStateSize);
223+ //uint32_t planStateSize;
224+ //getPlan(ar.compiler_cb, planStateSize);
225+ assert(thePlan != NULL);
226+ ZORBA_ASSERT(thePlan != NULL);
227 #endif
228 }
229 catch(...)
230
231=== modified file 'src/functions/udf.h'
232--- src/functions/udf.h 2012-01-14 21:58:23 +0000
233+++ src/functions/udf.h 2012-01-18 11:01:27 +0000
234@@ -20,6 +20,7 @@
235 #include "functions/function.h"
236
237 #include "compiler/expression/expr_base.h"
238+#include "zorbatypes/rclist.h"
239
240
241 namespace zorba
242@@ -131,17 +132,21 @@
243 bool theCacheResults;
244 bool theCacheComputed;
245
246+ rchandle<rclist<user_function*> > theLocalUdfs;//for plan serializer
247+
248 public:
249 SERIALIZABLE_CLASS(user_function)
250 user_function(::zorba::serialization::Archiver& ar);
251 void serialize(::zorba::serialization::Archiver& ar);
252+ void prepare_for_serialize(CompilerCB *compilerCB);
253
254 public:
255 user_function(
256 const QueryLoc& loc,
257 const signature& sig,
258 expr_t expr_body,
259- short kind);
260+ short kind,
261+ CompilerCB *compilerCB);
262
263 virtual ~user_function();
264
265
266=== modified file 'src/zorbaserialization/archiver.cpp'
267--- src/zorbaserialization/archiver.cpp 2011-07-13 01:56:45 +0000
268+++ src/zorbaserialization/archiver.cpp 2012-01-18 11:01:27 +0000
269@@ -27,6 +27,7 @@
270 #include "class_serializer.h"
271 #include "mem_archiver.h"
272
273+
274 namespace zorba
275 {
276
277@@ -112,7 +113,7 @@
278 current_level(0),
279 internal_archive(internal_archive),
280 theUserCallback(0),
281- compiler_cb(0),
282+ //compiler_cb(0),
283 dont_allow_delay_for_plan_sctx(false)
284 {
285
286@@ -195,6 +196,7 @@
287 ref_field = check_nonclass_pointer(type, orig_ptr);
288 if(ref_field)
289 {
290+ assert((field_treat != ARCHIVE_FIELD_NORMAL) || (ref_field->field_treat != ARCHIVE_FIELD_NORMAL));
291 if(get_is_temp_field_one_level() && (field_treat == ARCHIVE_FIELD_IS_PTR) && (allow_delay2 == ALLOW_DELAY))
292 allow_delay2 = DONT_ALLOW_DELAY;
293 if(field_treat == ARCHIVE_FIELD_NORMAL)
294@@ -309,6 +311,7 @@
295 }
296 if(ref_field)
297 {
298+ assert((field_treat != ARCHIVE_FIELD_NORMAL) || (ref_field->field_treat != ARCHIVE_FIELD_NORMAL));
299 if(get_is_temp_field_one_level() && (field_treat == ARCHIVE_FIELD_IS_PTR) && (allow_delay2 == ALLOW_DELAY))
300 allow_delay2 = DONT_ALLOW_DELAY;
301 if(field_treat == ARCHIVE_FIELD_NORMAL)
302
303=== modified file 'src/zorbaserialization/archiver.h'
304--- src/zorbaserialization/archiver.h 2011-10-03 09:18:49 +0000
305+++ src/zorbaserialization/archiver.h 2012-01-18 11:01:27 +0000
306@@ -202,7 +202,7 @@
307 SerializationCallback* theUserCallback;
308
309 public:
310- CompilerCB *compiler_cb;///to workaround user defined function compile-at-runtime
311+ //CompilerCB *compiler_cb;///to workaround user defined function compile-at-runtime
312 bool dont_allow_delay_for_plan_sctx;
313 public:
314 Archiver(bool is_serializing_out, bool internal_archive=false);
315
316=== modified file 'src/zorbaserialization/zorba_class_serializer.h'
317--- src/zorbaserialization/zorba_class_serializer.h 2011-07-07 12:05:43 +0000
318+++ src/zorbaserialization/zorba_class_serializer.h 2012-01-18 11:01:27 +0000
319@@ -28,6 +28,7 @@
320 #include "zorbaserialization/archiver.h"
321
322 #include "store/api/shared_types.h"
323+#include "diagnostics/assert.h"
324
325 #include <stdio.h>
326 #include <map>
327@@ -224,7 +225,8 @@
328 bool is_ref;
329 ENUM_ALLOW_DELAY allow_delay = ar.get_allow_delay();
330 is_ref = ar.add_compound_field("rchandle<T>", 0, !FIELD_IS_CLASS, "", &obj, ARCHIVE_FIELD_NORMAL);
331- if(!is_ref)
332+ assert(!is_ref);
333+ ZORBA_ASSERT(!is_ref);
334 {
335 T *p = obj.getp();
336 if(allow_delay != ALLOW_DELAY)
337@@ -242,10 +244,6 @@
338 ar.set_is_temp_field_one_level(false);
339 ar.add_end_compound_field();
340 }
341- else
342- {
343- assert(false);
344- }
345 }
346 else
347 {
348
349=== modified file 'src/zorbatypes/rchandle.h'
350--- src/zorbatypes/rchandle.h 2011-07-12 20:15:01 +0000
351+++ src/zorbatypes/rchandle.h 2012-01-18 11:01:27 +0000
352@@ -92,9 +92,9 @@
353
354 long getRefCount() const { return theRefCount; }
355
356- long* getSharedRefCounter() const { ZORBA_FATAL(0, ""); return NULL; }
357+ //long* getSharedRefCounter() const { ZORBA_FATAL(0, ""); return NULL; }
358
359- SYNC_CODE(RCLock* getRCLock() const { ZORBA_FATAL(0, ""); return NULL; });
360+ //SYNC_CODE(RCLock* getRCLock() const { ZORBA_FATAL(0, ""); return NULL; });
361
362 void addReference(long* sharedCounter SYNC_PARAM2(RCLock* lock)) const;
363
364
365=== added file 'src/zorbatypes/rclist.h'
366--- src/zorbatypes/rclist.h 1970-01-01 00:00:00 +0000
367+++ src/zorbatypes/rclist.h 2012-01-18 11:01:27 +0000
368@@ -0,0 +1,37 @@
369+/*
370+ * Copyright 2006-2008 The FLWOR Foundation.
371+ *
372+ * Licensed under the Apache License, Version 2.0 (the "License");
373+ * you may not use this file except in compliance with the License.
374+ * You may obtain a copy of the License at
375+ *
376+ * http://www.apache.org/licenses/LICENSE-2.0
377+ *
378+ * Unless required by applicable law or agreed to in writing, software
379+ * distributed under the License is distributed on an "AS IS" BASIS,
380+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
381+ * See the License for the specific language governing permissions and
382+ * limitations under the License.
383+ */
384+#include <list>
385+#include "common/common.h"
386+#include "zorbatypes/rchandle.h"
387+#pragma once
388+#ifndef ZORBA_REF_COUNTED_STD_LIST
389+#define ZORBA_REF_COUNTED_STD_LIST
390+
391+namespace zorba
392+{
393+
394+template <typename T>
395+class rclist : public RCObject, public std::list<T>
396+{
397+ SYNC_CODE(mutable RCLock lock;)
398+public:
399+ long* getSharedRefCounter() const { return NULL; }
400+ SYNC_CODE(RCLock* getRCLock() const { return &lock; });
401+};
402+
403+}//end namespace zorba
404+
405+#endif

Subscribers

People subscribed via source and target branches