Skip to content

Commit

Permalink
Fixed small bug & made the limits individually changable.
Browse files Browse the repository at this point in the history
  • Loading branch information
mvdwerve committed Jan 15, 2016
1 parent 2973571 commit 551cbf6
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 25 deletions.
16 changes: 8 additions & 8 deletions data.h
Original file line number Diff line number Diff line change
Expand Up @@ -268,24 +268,24 @@ class Data : public JSON::Object, private TupleHelper
* Set the max number of files
* @param value
*/
void maxfiles(int64_t value)
void maxfiles(int64_t mapper, int64_t reducer, int64_t finalizer)
{
// set the limit files property on the mapper, reducer and finalizer
object("mapper").object("limit").set("files", value);
object("reducer").object("limit").set("files", value);
object("finalizer").object("limit").set("files", value);
if (mapper) object("mapper").object("limit").set("files", mapper);
if (reducer) object("reducer").object("limit").set("files", reducer);
if (finalizer) object("finalizer").object("limit").set("files", finalizer);
}

/**
* Set the max number of bytes
* @param value
*/
void maxbytes(int64_t value)
void maxbytes(int64_t mapper, int64_t reducer, int64_t finalizer)
{
// set the limit files property on the mapper, reducer, and finalizer
object("mapper").object("limit").set("bytes", value);
object("reducer").object("limit").set("bytes", value);
object("finalizer").object("limit").set("bytes", value);
if (mapper) object("mapper").object("limit").set("bytes", mapper);
if (reducer) object("reducer").object("limit").set("bytes", reducer);
if (finalizer) object("finalizer").object("limit").set("bytes", finalizer);
}

/**
Expand Down
12 changes: 8 additions & 4 deletions extension.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,14 @@ extern "C" {
Php::ByVal("value", Php::Type::Numeric)
}).method("maxprocesses", &Job::maxprocesses, {
Php::ByVal("value", Php::Type::Numeric)
}).method("maxfiles", &Job::maxfiles, {
Php::ByVal("value", Php::Type::Numeric)
}).method("maxbytes", &Job::maxbytes, {
Php::ByVal("value", Php::Type::Numeric)
}).method("maxfiles", &Job::maxfiles, { // old behaviour causes all the same, new behaviour has differences
Php::ByVal("mapper", Php::Type::Numeric),
Php::ByVal("reducer", Php::Type::Numeric, false),
Php::ByVal("finalizer", Php::Type::Numeric, false)
}).method("maxbytes", &Job::maxbytes, { // old behaviour sets all values to the same value, new behaviour set individually
Php::ByVal("mapper", Php::Type::Numeric),
Php::ByVal("reducer", Php::Type::Numeric, false),
Php::ByVal("finalizer", Php::Type::Numeric, false)
}).method("maxmappers", &Job::maxmappers, {
Php::ByVal("value", Php::Type::Numeric)
}).method("maxreducers", &Job::maxreducers, {
Expand Down
18 changes: 11 additions & 7 deletions job.h
Original file line number Diff line number Diff line change
Expand Up @@ -171,11 +171,13 @@ class Job :
*/
Php::Value maxfiles(Php::Parameters &params)
{
// extract the number
int64_t maxfiles = params[0].numericValue();
// extract the number, old behavior is all the same value
int64_t mapperfiles = params[0].numericValue();
int64_t reducerfiles = params.size() >= 2 ? params[1].numericValue() : mapperfiles;
int64_t finalizerfiles = params.size() >= 3 ? params[2].numericValue() : mapperfiles;

// pass on to the implementation object
if (!_impl->maxfiles(maxfiles)) return nullptr;
if (!_impl->maxfiles(mapperfiles, reducerfiles, finalizerfiles)) return nullptr;

// allow chaining
return this;
Expand All @@ -188,11 +190,13 @@ class Job :
*/
Php::Value maxbytes(Php::Parameters &params)
{
// extract the number
int64_t maxbytes = params[0].numericValue();
// extract the number, old behavior is all the same value
int64_t mapperbytes = params[0].numericValue();
int64_t reducerbytes = params.size() >= 2 ? params[1].numericValue() : mapperbytes;
int64_t finalizerbytes = params.size() >= 3 ? params[2].numericValue() : mapperbytes;

// pass on to the implementation
if (!_impl->maxbytes(maxbytes)) return nullptr;
// pass on to the implementation object
if (!_impl->maxbytes(mapperbytes, reducerbytes, finalizerbytes)) return nullptr;

// allow chaining
return this;
Expand Down
18 changes: 13 additions & 5 deletions jobimpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,15 @@ class JobImpl
_directory.reset(new Directory());

// the directory exists, set this in the json, we want the cleanup and no server
_json.directory(_directory->relative(), true, "");
if (version() == 2) _json.directory(_directory->relative(), true, "");

// either a race job or an old mapreduce job; add the directory directly
else
{
// add the directory
_json.directory(_directory->relative());
}

}
catch (...)
{
Expand Down Expand Up @@ -262,13 +270,13 @@ class JobImpl
* @param value
* @return bool
*/
bool maxfiles(int value)
bool maxfiles(int mapper, int reducer, int finalizer)
{
// not possible if job has already started
if (_started) return false;

// set in the json
_json.maxfiles(value);
_json.maxfiles(mapper, reducer, finalizer);

// done
return true;
Expand All @@ -279,13 +287,13 @@ class JobImpl
* @param value
* @return bool
*/
bool maxbytes(uint64_t value)
bool maxbytes(uint64_t mapper, uint64_t reducer, uint64_t finalizer)
{
// not possible if job has already started
if (_started) return false;

// set in the json
_json.maxbytes(value);
_json.maxbytes(mapper, reducer, finalizer);

// done
return true;
Expand Down
1 change: 0 additions & 1 deletion tests/test.linecount.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ function assign($job, $path)
foreach($objects as $name => $object) {

$job->add($object->getPathName());

}
}

Expand Down

0 comments on commit 551cbf6

Please sign in to comment.