@@ -1448,8 +1448,11 @@ Result RestReplicationHandler::parseBatch(transaction::Methods& trx,
1448
1448
VPackStringRef bodyStr = _request->rawPayload ();
1449
1449
char const * ptr = bodyStr.data ();
1450
1450
char const * end = ptr + bodyStr.size ();
1451
-
1452
- VPackBuilder builder (&basics::VelocyPackHelper::strictRequestValidationOptions);
1451
+
1452
+ VPackOptions builderOptions = basics::VelocyPackHelper::strictRequestValidationOptions;
1453
+ builderOptions.paddingBehavior = VPackOptions::PaddingBehavior::UsePadding;
1454
+
1455
+ VPackBuilder builder (&builderOptions);
1453
1456
1454
1457
// First parse and collect all markers, we assemble everything in one
1455
1458
// large builder holding an array
@@ -1493,12 +1496,15 @@ Result RestReplicationHandler::parseBatch(transaction::Methods& trx,
1493
1496
1494
1497
TRI_ASSERT (doc.isObject ());
1495
1498
bool checkKey = true ;
1499
+ bool checkRev = generateNewRevisionIds;
1496
1500
for (auto it : VPackObjectIterator (doc, true )) {
1497
1501
// only check for "_key" attribute here if we still have to.
1498
1502
// once we have seen it, it will not show up again in the same document
1499
1503
bool const isKey = checkKey && (arangodb::velocypack::StringRef (it.key ) == StaticStrings::KeyString);
1500
1504
1501
1505
if (isKey) {
1506
+ // _key attribute
1507
+
1502
1508
// prevent checking for _key twice in the same document
1503
1509
checkKey = false ;
1504
1510
@@ -1515,17 +1521,23 @@ Result RestReplicationHandler::parseBatch(transaction::Methods& trx,
1515
1521
// with MMFiles dumps from <= 3.6
1516
1522
documentsToRemove.erase (it.value .copyString ());
1517
1523
}
1518
- }
1524
+
1525
+ documentsToInsert.add (it.key );
1526
+ documentsToInsert.add (it.value );
1527
+ } else if (checkRev && arangodb::velocypack::StringRef (it.key ) == StaticStrings::RevString) {
1528
+ // _rev attribute
1519
1529
1520
- documentsToInsert.add (it.key );
1530
+ // prevent checking for _rev twice in the same document
1531
+ checkRev = false ;
1521
1532
1522
- if (generateNewRevisionIds &&
1523
- !isKey &&
1524
- arangodb::velocypack::StringRef (it.key ) == StaticStrings::RevString) {
1525
1533
char ridBuffer[arangodb::basics::maxUInt64StringSize];
1526
1534
RevisionId newRid = physical->newRevisionId ();
1535
+
1536
+ documentsToInsert.add (it.key );
1527
1537
documentsToInsert.add (newRid.toValuePair (ridBuffer));
1528
1538
} else {
1539
+ // copy key/value verbatim
1540
+ documentsToInsert.add (it.key );
1529
1541
documentsToInsert.add (it.value );
1530
1542
}
1531
1543
}
@@ -1629,15 +1641,18 @@ Result RestReplicationHandler::processRestoreDataBatch(transaction::Methods& trx
1629
1641
std::string const & collectionName,
1630
1642
bool generateNewRevisionIds) {
1631
1643
// we'll build all documents to insert in this builder
1632
- VPackBuilder documentsToInsert;
1644
+ VPackOptions vpackOptions;
1645
+ vpackOptions.paddingBehavior = VPackOptions::PaddingBehavior::UsePadding;
1646
+
1647
+ VPackBuilder documentsToInsert (&vpackOptions);
1633
1648
std::unordered_set<std::string> documentsToRemove;
1634
1649
Result res = parseBatch (trx, collectionName, documentsToInsert, documentsToRemove, generateNewRevisionIds);
1635
1650
if (res.fail ()) {
1636
1651
return res;
1637
1652
}
1638
1653
1639
1654
OperationOptions options (_context);
1640
- options.silent = false ;
1655
+ options.silent = true ;
1641
1656
options.ignoreRevs = true ;
1642
1657
options.isRestore = true ;
1643
1658
options.waitForSync = false ;
@@ -1679,6 +1694,42 @@ Result RestReplicationHandler::processRestoreDataBatch(transaction::Methods& trx
1679
1694
<< " documents for restore: " << opRes.result .errorMessage ();
1680
1695
return opRes.result ;
1681
1696
}
1697
+
1698
+ if (opRes.countErrorCodes .empty ()) {
1699
+ // no detailed errors reported. all good
1700
+ return Result ();
1701
+ }
1702
+
1703
+ // at least one error occurred
1704
+ if (opRes.slice ().isArray ()) {
1705
+ // Now go through the individual results and check each errors
1706
+ VPackArrayIterator itRequest (requestSlice);
1707
+ VPackArrayIterator itResult (opRes.slice ());
1708
+
1709
+ while (itRequest.valid ()) {
1710
+ VPackSlice result = *itResult;
1711
+ VPackSlice error = result.get (StaticStrings::Error);
1712
+ if (error.isTrue ()) {
1713
+ error = result.get (StaticStrings::ErrorNum);
1714
+ if (error.isNumber ()) {
1715
+ auto code = ErrorCode{error.getNumericValue <int >()};
1716
+ error = result.get (StaticStrings::ErrorMessage);
1717
+ if (error.isString ()) {
1718
+ return { code, error.copyString () };
1719
+ }
1720
+ return { code };
1721
+ }
1722
+ }
1723
+ itRequest.next ();
1724
+ itResult.next ();
1725
+ }
1726
+ }
1727
+
1728
+ // if we get here, we didn't have a detailed array with results.
1729
+ // so we need to stick to the error code map, which is all we got
1730
+ TRI_ASSERT (!opRes.countErrorCodes .empty ());
1731
+ ErrorCode ec = (*opRes.countErrorCodes .begin ()).first ;
1732
+ return {ec};
1682
1733
} catch (arangodb::basics::Exception const & ex) {
1683
1734
LOG_TOPIC (" 8e8e1" , WARN, Logger::CLUSTER)
1684
1735
<< " could not insert documents for restore exception: " << ex.what ();
@@ -1692,30 +1743,6 @@ Result RestReplicationHandler::processRestoreDataBatch(transaction::Methods& trx
1692
1743
<< " could not insert documents for restore exception." ;
1693
1744
return Result (TRI_ERROR_INTERNAL);
1694
1745
}
1695
-
1696
- // Now go through the individual results and check each errors
1697
- VPackArrayIterator itRequest (requestSlice);
1698
- VPackArrayIterator itResult (opRes.slice ());
1699
-
1700
- while (itRequest.valid ()) {
1701
- VPackSlice result = *itResult;
1702
- VPackSlice error = result.get (StaticStrings::Error);
1703
- if (error.isTrue ()) {
1704
- error = result.get (StaticStrings::ErrorNum);
1705
- if (error.isNumber ()) {
1706
- auto code = ErrorCode{error.getNumericValue <int >()};
1707
- error = result.get (StaticStrings::ErrorMessage);
1708
- if (error.isString ()) {
1709
- return { code, error.copyString () };
1710
- }
1711
- return { code };
1712
- }
1713
- }
1714
- itRequest.next ();
1715
- itResult.next ();
1716
- }
1717
-
1718
- return Result ();
1719
1746
}
1720
1747
1721
1748
// //////////////////////////////////////////////////////////////////////////////
0 commit comments